sheehan/grails-handlebars-resources

Cannot use handlebars_runtime with grails.resources.debug = true

nolanlawson opened this issue · 3 comments

Love what you've done with this plugin, but I've run into a workflow issue.

I would like to use the handlebars_runtime dependency to prevent having to compile on the client side (really important for mobile clients). However, I also like setting grails.resources.debug=true in the Config.groovy while I'm in development mode, so that my JS and CSS files can get automatically reloaded.

Problem is, in debug mode, the resource mappers don't run (of course). So the raw handlebars file gets transferred instead, and in Chrome I see the error:

Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:8080/[...]/filename.hbs[...]
Uncaught SyntaxError: Unexpected token < 

And of course, I can't call Handlebars.templates['my-template-file'] on the client side like I normally would, since it wasn't precompiled.

Of course I can just set grails.resources.debug=false, but then I don't get automatic reloading of JS/CSS, meaning I have to keep re-launching grails run-app every time I change a line in a JS file.

Unfortunately, since Grails doesn't seem to allow per-mapper resource debugging, I don't see an easy way to fix this. So I guess my question is: what workflow do you use with your own plugin? Do you just re-launch grails run-app whenever you change a JavaScript file?

As an aside, I searched GitHub for instances of people using your plugin and I found two groups: 1) those who were not using grails.resources.debug=true, and 2) those who were, but who had commented out your plugin. So it seems I'm not the only one who has had issues. :)

Thanks again for your excellent work.

Hi, thanks for the feedback! I never use the debug flag, but the JS/CSS still reloads automatically when the file is changed. Are you sure that doesn't work for you?

Thanks for the tip. I double-checked, and it looks like this problem is actually caused by disabling the cached resources plugin.

So basically, using this in my dev environment configuration does not refresh the resources (JS, HBS, or otherwise):

grails.resources.mappers.hashandcache.enabled = false

But I can disable bundling/minification and it will work just fine.

grails.resources.mappers.bundle.enabled = false
grails.resources.mappers.yuicssminify.disable = true
grails.resources.mappers.yuijsminify.disable = true

So I guess the take-home is to not use grails.resources.debug, and instead to selectively disable mappers that you don't want in dev mode (e.g. bundling) while enabling mappers you do want (e.g. handlebars).

I'm also closing this bug because I laid it on the wrong doorstep. Thanks for your help!

Curiouser and curiouser. Apparently the cached resources plugin is the only thing ensuring that resources get refreshed - uninstalling it results in nothing ever getting refreshed. Starting to wonder if it's a general problem in Grails 2.1.1/Resources 1.2.