precompile handlebar templates

こ雲淡風輕ζ 提交于 2019-12-04 12:50:23

问题


I'm wondering what's the best way to save precompiled handlebar templates and include them in an HTML file.

The site: http://handlebarsjs.com/precompilation.html simply advises to call

handlebars infile -f outfile

I put a template in a file and called the command. I got a JS file containing a function program1 How would I now compile a second template? The sample at http://jsperf.com/jquery-template-vs-handlebars contains multiple functions named program[1-9](...) I assume they somehow must be generated. Is it good advice to store precompiled templates at all? I saw samples embedding script or link tags in an HTML file and traversing these and via AJAX loading the templates and compiling them dynamically.

Best, Bernhard


回答1:


If you want multiple files, list them in the command like so

handlebars file1 file2 file3 -f outfile

You DO want to store precompiled files for your production site as it drastically cuts down on load time.




回答2:


You should use

handlebars /path/to/templates/*.handlebars -f /path/to/output/templates.js



回答3:


Easiest way, provided that you want to keep your templates with html extension is this: handlebars html

that is: handlebars ./ -e html -f precompiled_templates.js



来源:https://stackoverflow.com/questions/10710891/precompile-handlebar-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!