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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:29+00:00 2026-05-25T11:37:29+00:00

At the moment I have a single html page that has 4 templates in

  • 0

At the moment I have a single html page that has 4 templates in it and will have many more. Is it possible to put the templates in different files and “import” them in? Can I define them in a .js file?

I’m using jQquery template plugin: http://api.jquery.com/category/plugins/templates/

My code looks like the examples!

  • 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-25T11:37:30+00:00Added an answer on May 25, 2026 at 11:37 am

    I mostly agree with this answer’s spin: Where to keep html templates?
    You’re already doing the right thing, because of the KISS principle.

    Depending on how many templates you’ll end up with (you mentioned “many more”), you may want to separate them from your main page. There are a couple reasons for this.

    One reason would again be the KISS principle. Too many templates could make your source code difficult to navigate. Your editor or IDE might have you covered on this already. If not, this may be a good reason to put your templates into separate files.

    The other reason would be for performance. If you serve the HTML file by itself, without the templates, your page will arrive at the client and begin rendering much sooner. You can also allow the client to cache some templates and only load new ones when they change. This will make future visits to your site initialize much faster.

    If performance is especially important, you might consider a mixture of the two approaches. You would include the essential templates, the ones that assemble the basic structure of your page, in the main HTML page. Then, the optional templates can be fetched after the page loads and/or right before they’re needed. To include the essential templates, you could use server-side templating.

    Regarding your original question, as to where to store them, I say that you should put them wherever makes sense to you. Then, see Dave Ward’s article on using external templates with jQuery templates for info on how build and fetch your templates. Here’s the essential snippet of code:

    // Asynchronously our PersonTemplate's content.
    $.get('PersonTemplate.htm', function(template) {
    
      // Use that stringified template with $.tmpl() and 
      //  inject the rendered result into the body.
      $.tmpl(template, person).appendTo('body');
    });
    

    Then, see An Introduction to jQuery Templates, by Stephen Walther and jump to the section titled “Remote Templates”. He has an example there which fetches and compiles the template only once, but makes it possible to render multiple times. Here are the essential snippets:

    // Get the remote template
    $.get("ProductTemplate.htm", null, function (productTemplate) {
    
        // Compile and cache the template
        $.template("productTemplate", productTemplate);
    
        // Render the products
        renderProducts(0);
    });
    
    function renderProducts() {
        // Get page of products
        var pageOfProducts = products.slice(pageIndex * 5, pageIndex * 5 + 5);
    
        // Used cached productTemplate to render products
        $.tmpl("productTemplate", pageOfProducts).appendTo("#productContainer");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im creating a program that will compile java files, at the moment i have
My boss has asked for a page that will not change to have two
I'm building a single-page application. At the moment, I also have several independent pages
At the moment, I have a whole bunch of html + php files with
I have a database containing a single huge table. At the moment a query
At the moment I have a DocumentViewer in a WPF window that displays an
At the moment I have a combobox that is populated from the name fields
For the moment assume that I have access to my own server so I
I have a form that submits through Ajax, which works perfectly at the moment.
At the moment I'm working on a system that caches dynamically created files, nothing

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.