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 5960735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:52:02+00:00 2026-05-22T18:52:02+00:00

I am using jquery templates on both the server-side and client-side. I’m using the

  • 0

I am using jquery templates on both the server-side and client-side. I’m using the jqtpl and express modules on Node.js for the server, and I have jquery and its template plugin for the client.

Wherever possible the client recieves JSON instead of html, and builds the template itself, using the HTML5 history api to change url and allow session navigation. If this isn’t possible, the server does the templating instead and sends html.

Both the server and the client have the exact same templates, but the server has them in the form of 12 .html files, and the client has them in the form of an object in a .js file.

Each time I change or add a template, I have to alter the client .js file to be the same, which is a bit of a pain.

What I would like to do is have the .js file dynamically take all of the .html files in my templates folder and compile them into an object. Once I had finished development, this file would be cached, as it no longer needs to look for changes.

  • 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-05-22T18:52:03+00:00Added an answer on May 22, 2026 at 6:52 pm

    What I was looking for was Node’s file system module:

    http://nodejs.org/docs/v0.4.8/api/fs.html

    I used fs.readdir to find all of the template files in the folder, then iterated through the array that produced to read all of its containing files.

    var templates = {};
    fs.readdir("./templates", function(err, files) {
        for(var i = 0, len = files.length; i<len; i++) {
            fs.readFile("./templates/" + files[i], function (err, data) {
                if (err) {
                    throw err
                }
                templates[files[i]] = data;
            });
        }
    }
    

    And then in express:

    app.get("/templates.js", function(req, res){
        res.header("Content-Type", "text/javascript");
        res.end("var templates = { " + JSON.stringify(templates) + " }; ");
    });
    

    However, I found that server-side templating was better suited to my needs, and where appropriate, I now send rendered HTML in my JSON responses instead of just data.

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

Sidebar

Related Questions

I'm using Knockout with jQuery and jQuery templates. Assume that I have a template
I am using jQuery Templates successfully but I have a blur function that is
Update I want to avoid compiling the templates client-side, and have them compile during
Using jQuery, how would you find elements which have a particular style (eg: float:
I have two views: create and edit. Both share a strongly typed editor template
I am using the jquery-tmpl template library to build a dynamic <select> list. In
How to change image resolution using jQuery.I have applied a image on body background
So I am pretty new to both Django and Javascript (I am using JQuery)
I'm using Drupal 6.x. This is my code on my node-product.tpl.php template. I've created
I am using Jquery templates to display incoming JSON data I would like to

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.