如何防止 Grails 缓存旧版本的 gsp 文件?
我正在对 /grails-app/views/index.gsp 进行修改。
当我保存文件并在 Firefox 中刷新 http://localhost:8080/index.gsp 时,我获取文件的旧版本。
有没有办法阻止 Grails 缓存和渲染旧版本的文件?
(我尝试重新启动服务器并清除 Firefox 的缓存。)
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我们不能使用这样的过滤器吗?
can't we use a filter like this?
似乎没有一个简单的方法可以做到这一点,但工作量并不大。我的解决方案对呈现 GSP 的 servlet(以及用于非 GSP 请求的控制器)进行子类化。
这是 servlet 子类:
您需要替换 web.xml 中的原始文件(运行“grails install-templates”并编辑 src/templates/war/web.xml):
并且您可能也想做同样的事情对于基于控制器的响应,因此要使用此控制器子类:
并且您需要在 grails-app/conf/spring/resources.groovy 中注册它以覆盖常规 Spring bean:
共享标头设置代码可能应该被提取到实用程序类中,而不是像我在这里那样复制/粘贴。
There doesn't seem to be a simple way to do this, but it's not much work. My solution subclasses the servlet that renders GSPs (and also the controller that's used for non-GSP requests).
Here's the servlet subclass:
and you'll need to replace the original in web.xml (run "grails install-templates" and edit src/templates/war/web.xml):
and you'll probably also want to do the same for Controller-based responses, so to do that use this controller subclass:
and you'll need to register it in grails-app/conf/spring/resources.groovy to override the regular Spring bean:
The shared header-setting code should probably be extracted into a utility class instead of being copy/pasted like I did here.
grails 中有一个用于控制缓存行为的插件,称为 Cache Headers:
http://grails.org/plugin/cache-headers
There's a plugin for controlling cache behavior in grails called Cache Headers:
http://grails.org/plugin/cache-headers
确保您正在开发模式下运行(即 grails run-app 而不是 grails test|prod run-app,测试和生产将启用页面缓存。如果您处于开发模式,请尝试在单击时按住 Shift 键火狐刷新。
Make sure you are running in dev mode (i.e., grails run-app and not grails test|prod run-app, test and production will enable caching of the pages. If you are in dev mode, try holding the shift key when click the Firefox refresh.
如果您只想在开发时禁用浏览器缓存,可以使用 Firefox 的 Web Developer 插件:
https://addons.mozilla.org/en-US/firefox/addon/60
安装此插件 &选择“禁用缓存”。请记住,这将禁用所有网站的缓存。
If you simply want to disable cache for your browser while development, you can use Web Developer add on for Firefox:
https://addons.mozilla.org/en-US/firefox/addon/60
Install this add on & choose "Disable cache". Remember, that will disable caching for all the websites.
仅出于开发目的,请尝试按 ctrl+F5,它也会刷新页面和缓存。用于在生产中缓存内容并提高页面查找 ui-性能插件和 grails 资源插件的性能。
For just development purposes try pressing ctrl+F5, it will refresh the page and the cache too.. for caching things on production and improving performance of page lookup ui-performance plugin and resources plugins of grails.