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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:15:41+00:00 2026-05-30T01:15:41+00:00

I recent came across Javascript templates and have become quite intrigued. I am building

  • 0

I recent came across Javascript templates and have become quite intrigued.

I am building a large PHP application using the MVC pattern. Templating is handled by the rather awesome Twig.

I recently came across a javascript implementation of twig.

I have also read quite a bit about using javascipt template engines.

Now, in my application, the application generates a the full page for standard requests as fallback for users without javascript. For AJAX requests, it can generate the content part of the page (no <head>, <body> etc).

The ajax response object is currently just a the rendered HTML content, which is then inserted into DOM.

Should I instead return a response object containing a compiled javascript template and the objects to be inserted into the template? What are the benefits of doing that?

From the posts I have read, the javascript templates were only small snippets representing a small part of a page, for example displaying a comment on a blog post during the instant that the user has submitted it.

Are javascript templates only useful for inserting these sort of small “pieces” in a page?

  • 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-30T01:15:43+00:00Added an answer on May 30, 2026 at 1:15 am

    Yes

    A recent project I was on got “client-side template fever” and we used the dang things for every single template.

    With every template library I’ve used (which is two or three), the error messages you get are not very good. If you have a huge template that operates on a fair amount of data, you’ll quickly find the u.foo is null or not an object error message increasingly frustrating.

    The best-practices I’ve settled on is:

    • Return a full HTML snippet (from the server) if it’s a template that is seldom loaded. If you are only loading that HTML once on a page, then you might as well send it down populated right? This also encourages you to keep your logic up on the server, where it probably belongs.
    • Use client-side templates for small, repeated templates. Your blog comment example is probably a good one. I’ve found the most success when my client-side templates are pretty small (< 10 lines)
    • Use a logic-less template engine. The more logic allowable in a template, the harder they are to read/maintain. Plus, some of that logic should probably be in your business layer, not down in some JavaScript template. In other words, they force you to separate your presentation from your logic (which is good).

    PS: It is cool that both your client and server-side templates could use the same templating engine. This will make developers on your project much more productive.

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

Sidebar

Related Questions

A recent question came up about using String.Format(). Part of my answer included a
I have recenty came across a problem while importing older data than my current
I came across a recent Audit report in our company for the code we
I was doing a bit research and I came across this comment. I have
Recent conversations with colleagues have produced varying points of view on this matter. What
This recent question about sorting randomly using C# got me thinking about the way
I am using Derby database with Java and Eclipse. I have a table which
In my application I have use some data ValueCell (something like 20) and I
I was reading the ctypes tutorial, and I came across this: s = Hello,
I'm writing example code for everything in HTML and CSS. I came across display:inline

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.