Grails won't load changes done in static resources (except when restarting)

时光总嘲笑我的痴心妄想 提交于 2020-01-01 08:44:27

问题


I have an annoying problem with my new grails app. I'm trying to mock up a design for a site that I will be making but whenever I do changes in my css it won't affect the running application. No matter how big changes I do I have to stop the application and then run it again.

This is very frustrating, I've turned of cache in Chrome and even if I go to the specific document the resource is still the old. What can I do to solve this problem? I can make changes in my gsp files and the changes will appear but not in my css.

I am currently loading the resource within a layout file like this:

<link rel="stylesheet" href="${resource(dir: 'css', file: 'app.css')}" type="text/css">

If you need me to provide any more information, please just ask. I am using grails 2.2.0.


回答1:


Add this to your Config.groovy (probably just for development)

grails.resources.debug = true

Read the docs for more info.




回答2:


It looks like Gregg's answer doesn't work for 1.3.7 (maybe that is something added in 2.x?). A method I found that makes quick CSS updates possible is to include a separate GSP as a template in the page header.

That is, create a file called "_css.gsp" (underscore prefix is required) in the same directory as your view files, fill it with standard css surrounded by html style tags, and then include the following in your layout header or page:

<g:render template="css" />

With that in place, the content of _css.gsp is injected into the page. And I can make changes to _css.gsp and they are immediately reflected after page refresh without having to restart Grails. Hope this helps someone in Grails pre-2.x!



来源:https://stackoverflow.com/questions/15072535/grails-wont-load-changes-done-in-static-resources-except-when-restarting

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