如何处理GWT主题CSS文件的缓存 [英] How to handle caching of GWT theme CSS files
问题描述
我有一个使用Struts / Tiles / JSP编写的应用程序,我添加了一个GWT应用程序。我的应用程序的非GWT部分通过实际写出的css文件的版本号从我的svn存储库附加,像这样styles.css?svnbuild = 12345处理css缓存。这样我可以告诉浏览器永远缓存这些CSS文件,当我部署一个新版本的所有我的用户立即下载它。
I've got an app written with Struts/Tiles/JSP that I'm adding a GWT app to. The non-GWT portion of my app handles css caching by actually writing out the css file with a version number taken from my svn repository attached, like this "styles.css?svnbuild=12345". That way I can tell the browser to cache those css files forever and when I deploy a new version all my users download it immediately.
现在我移动到GWT应用程序,我喜欢它如何使用longmd5sum.cache.css作为文件名,所以我仍然可以告诉浏览器永远缓存它。问题是,与我的主题相关联的css文件,如gwt-standard.css,没有强名称,并且没有附加我的svnbuild参数。每当我部署我的应用程序的新版本,用户仍然看到的旧版本的css,这使它看起来错误。
Now I'm moving on to the GWT app and I love how it uses "longmd5sum.cache.css" as the filename so I can still tell the browser to cache it forever. The problem is that the css files associated with my theme, like "gwt-standard.css", don't have a strong name and don't have my svnbuild parameter attached. Whenever I deploy a new version of my app, users are still seeing the old version of the css which makes it look wrong.
有没有人找出最佳实践处理缓存gwt主题css文件?在附加css到文档时,有没有办法附加svnbuild参数或类似的东西?
Has anyone figured out a best practice for handling caching of gwt theme css files? Is there a way I can append an svnbuild parameter or something similar when appending the css to the document?
推荐答案
所以在我发布了这个我挖掘到GWT源代码,并找到一些链接关于创建GWT自定义链接器。
Ok. So after I posted this I dug into the GWT source code and found some links about creating a GWT custom linker.
http://development.lombardi.com/?p=29
http://code.google.com/webtoolkit/doc/1.6/DevGuideOrganizingProjects.html
这里是我用自己的链接器解决它。首先我制作了一个扩展标准IFrameLinker的链接器类:
Here's how I solved it with my own linker. First I made a linker class that extends the standard IFrameLinker:
@LinkerOrder(LinkerOrder.Order.PRIMARY)
public class MyLinker extends IFrameLinker {
protected String generateStylesheetInjector(String stylesheetUrl) {
stylesheetUrl = stylesheetUrl + "?buildtime=" + System.currentTimeMillis();
return super.generateStylesheetInjector(stylesheetUrl);
}
}
之后,它只是告诉你的模块使用您的自定义链接器。在您的module.gwt.xml文件中:
After that it's just a matter of telling your module to use your custom linker. In your module.gwt.xml file:
<module>
<define-linker name="mylinker" class="com.company.gwt.core.linker.MyLinker" />
<add-linker name="mylinker" />
</module>
刚刚试过了,现在在我的nocache.js文件中,每次编译时输出一个新的时间戳。我的用户可以永远缓存css文件,他们将下载一个新的,当我部署一个新版本的应用程序。
Just tried it out and now in my nocache.js file it outputs a new timestamp every time I compile. My users can cache the css file forever and they will download a new one automatically whenever I deploy a new version of the app.
这篇关于如何处理GWT主题CSS文件的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!