IMHO it really comes down to how many templates you have. When your site is first starting out and you don't have a lot of templates, keeping them all in script
tags on a single HTML page makes a lot of sense.
However, as your number of templates grows, that soon becomes unwieldy; before long you're using server-side logic to concatenate a bunch of separate template files in to your master HTML file, and at that point I think it makes perfect sense to start considering other approaches.
Personally my company's codebase started out with script
tags in an HTML file, but as we've since grown (and started using require
) and now now we have tens if not hundreds of .handlebars
(or more commonly, .hbs
) files for all of our templates. We bring these in to our Javascript using Alex Sexton's HBS plug-in (https://github.com/SlexAxton/require-handlebars-plugin) for require, and that works great because:
- we get to use our standard
require
system for our templates - templates get compiled to a single compressed JS file when we use the require optimizer
- we can configure our IDEs to treat
.handlebars
files as HTML, giving us the appropriate syntax coloring and such when we edit them
I'm not sure which templating system you're using, but if you're using Handlebars and already using Require then the HBS plug-in is a great way to. If you use a different templating system you likely can find a similar plug-in for Require (if that system is popular enough), or even write your own using the HBS one as a basis.
For anyone with a decent number of templates, I think a system like that (especially for anyone already using Require) makes a whole lot more sense than script
tags.