2

I have been researching methods for pre-compiling my _underscore templates and am beginning to think that 99% of people who are pre-compiling their templates seem to be running node.

This makes me think that maybe pre-compiling is intended to only be beneficial for rendering templates on the server instead of the client.

Is this true?

Is there any benefit in compiling temnplates on the server which will only be rendered in the client?

Nippysaurus
  • 20,110
  • 21
  • 77
  • 129

1 Answers1

3

"Really only useful" is a little subjective, don't you think? If you're asking about whether it's more important to pre-compile templates used server-side as opposed to client-side, it usually is, simply because a server is going to have to render them potentially several thousand times a second so it's wasteful to have to compile them each time they're rendered.

In a client-side app, the main concern is whether there's any user-noticeable slowdown associated with rendering templates. There usually isn't, and if there is, generally only a few (maybe partial templates used to build large list views) are responsible. So in most client-side apps, pre-compiling templates is a form of premature optimization.

ebohlman
  • 14,795
  • 5
  • 33
  • 35
  • You are right, that was a little subjective so made a small update. however you did interpret my question very well and have provided me with the information I need. Thank you :) – Nippysaurus Aug 23 '12 at 04:25
  • I'll add that pre-compiling templates meant for client-side rendering will actually increase the amount of data that needs to be sent from the server to the client (templating languages are generally more compact than the JS code they generate when compiled), though I have a hard time imagining a scenario where that would actually matter (again, beware of premature optimization). – ebohlman Aug 23 '12 at 06:12