Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to precompile and run precompiled js server side #36

Open
davich opened this issue Feb 26, 2015 · 1 comment
Open

How to precompile and run precompiled js server side #36

davich opened this issue Feb 26, 2015 · 1 comment

Comments

@davich
Copy link

davich commented Feb 26, 2015

I'm not sure if this is broken, or if I'm just doing it wrong. But there is no documentation on how to precompile templates and then load the precompiled template and call it.

I'm generating html on the server, but want to precompile the templates (for performance reasons) and save them as .js. Then at runtime, load the js file and call it with an options hash to generate html.

I see in Handlebars::Context there is a precompile function but it seems to produce different output from npm's handlebars precompile. And once I have it, I can't seem to load it back in, and call it.
I've tried Handlebars::Context.new.handlebars.template(str).apply({}), and variations of that. But still can't get something working.

Can someone update the docs on this, if the functionality is there and working? Or otherwise fix this.

Thanks in advance

@kuadrosx
Copy link

Hi, I'm trying todo the same

What I found that Handlebars.precompile returns 'js code' which is used by '../dist/cjs/precompiler' and this script generates a javascript that can be used by handlebars.runtime.js

So, to generate a precompiled template that can be used in runtime you will have to write an script similar to cjs/precompiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants