• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Server Side vs Client Side Templating

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Up to this point I have been using server side templating which basically means I send a request to the server via ajax and the server renders an HTML snippet back in the response which I then throw inside some container on the page.

Another recently popular approach is to leave the templating to the client and just return the data which is then fed into a JavaScript template engine.

I'm curious if there is "best practice" on which to choose or if it is just preference or if one is (nearly) always better than the other?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently planning on using jQuery's client-side templating because I will be communicating directly with a REST API on a server that's not capable of performing server-side templating. I'll be using jQuery's tmpl() plugin.

If I have a choice of either, I usually let the server do the templating. The client-side stuff is complicated enough as it is, so I like to let the server do the heavy lifting when possible where (I feel) it's easier to keep a handle on the complexity.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good points Bear. Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am finding something else about client side templating that seems significant. If doing the template rendering on the server a particular response is roughly 2400 in length. Just sending the data to the client and allowing the client to render the template sends a response of roughly 160 in length. The next step is to look at caching. I know that jQuery.tmpl() has some caching techniques to speed up template rendering. The server will always need to send the same amount of data regardless. So to me, this is looking like a winning point for client side; at least from a "everything is a nail" approach.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it really comes down to performance.

If the clientside can loop through the response that comes back and do the replacements in a reasonable amount of time, than it is worth it.

Eric
 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic