Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8163049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:55:57+00:00 2026-06-06T18:55:57+00:00

I am using jQuery templates to mark up my JSON. I am wondering if

  • 0

I am using jQuery templates to mark up my JSON. I am wondering if anyone has an elegant solution to precompile them into javascript on the server so as to keep the browser from having to do so each time.

I am aware of the following post:

pre-compile JavaScript templates to functions on project build

and I understand that I could use

https://github.com/wookiehangover/jquery-tmpl-jst

but I am hoping that there is something more elegant. For instance, how about an HttpModule that could be set to process request for *.jst files and would compile it and return back the resulting JS.

I’m not sure if this exist yet, but assuming if one could get the jquery-tmpl-jst project to run serverside, it seems fairly easy to build the HttpModule.

Any help is appreciated. If the module doesn’t exist, I will consider writing it if I can sort out how to get the actual compiling to work.

UPDATE

I just found this library. It isn’t an HttpModule, but it looks like it implements the jQuery template compiling serverside. Just not sure if it is fully implemented or not yet.

https://github.com/awhatley/jquery-tmpl.net

UPDATE

Well it looks like the library above is actually executing jQuery templates on the server in .Net so it never gets the javascript to the jQuery compiled format. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:55:58+00:00Added an answer on June 6, 2026 at 6:55 pm

    The first option is to use Cassette.Web (See documentation, get it with NuGet). Take in account that it will add about 6 dependent packages to your project as well. We did not need all this additional stuff so we decided to extract required part and it was quite a simple task:

    So the second option is

    1. Get some JS engine for .NET (we used Jurassic as Cassette.Web did)
    2. Download JS extract from jQuery-tmpl plugin used in Cassette.Web.
    3. Execute downloaded JS file in JS engine.
    4. Execute “buildTmplFn” JS function in JS engine passing to it your template as an argument
    5. Whoa-la, get a compiled template as a return value.

    Example:

    using Jurassic;
    ...
    private static string CompileTemplates(string sourceDirectory)
    {
        var resultBuilder = new StringBuilder();
        var scriptEngine = new ScriptEngine();
    
        scriptEngine.Execute(Properties.Resources.jqueryTmplCompiler);
    
        var templates = Directory.GetFiles(sourceDirectory, "*.htm?");
        if(templates.Count() > 0)
        {
            foreach (var filePath in templates)
            {
                Console.WriteLine("Compiling " + Path.GetFileName(filePath));
                string templateText = File.ReadAllText(filePath);
                string templateName = Path.GetFileNameWithoutExtension(filePath);
                string precompiledTemplate = scriptEngine.CallGlobalFunction<string>("buildTmplFn", templateText);
                resultBuilder.AppendFormat("$.template('{0}', {1});\n", templateName, precompiledTemplate);
            }
            Console.WriteLine("Templates successfully precompiled.");
        }
        else
        {
            ErrorExit("No templates found in Source Directory " + sourceDirectory);
        }
    
        return resultBuilder.ToString();
    }
    

    This example assumes that JS file downloaded at the second step is stored in resources of the current project.

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JQuery Templates to render a number of tables from a JSON
I'm using jquery templates to populate a table. I'm wondering if it's possible to
I am using jquery templates on both the server-side and client-side. I'm using the
I am using Jquery templates to display incoming JSON data I would like to
i've just started using jQuery Templates as my javascript template engine. My question is,
Rebecca Murphy talks about using jQuery templates. The JSON that Rebecca uses looks like:
I'm trying to display JSON data in a table using nested jQuery templates. I
@swatkins gave a fantastic answer to his own question about using jQuery templates with
Context: HTML widgets generated using a Django ModelForm and template, jQuery 1.3.2, JavaScript on
I'm using jtemplates (jquery plugin) as my templating solution which rocks by the way!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.