如何处理 GWT 主题 CSS 文件的缓存
我有一个用 Struts/Tiles/JSP 编写的应用程序,我正在向其中添加 GWT 应用程序。我的应用程序的非 GWT 部分通过实际写出带有从我的 svn 存储库获取的版本号的 css 文件来处理 css 缓存,如“styles.css?svnbuild=12345”。这样我就可以告诉浏览器永久缓存这些 css 文件,当我部署新版本时,所有用户都会立即下载它。
现在我将继续使用 GWT 应用程序,我喜欢它使用“longmd5sum.cache.css”作为文件名的方式,这样我仍然可以告诉浏览器永久缓存它。问题是与我的主题关联的 css 文件(例如“gwt-standard.css”)没有强名称,也没有附加我的 svnbuild 参数。每当我部署应用程序的新版本时,用户仍然会看到旧版本的 CSS,这使其看起来错误。
有没有人找到处理 gwt 主题 css 文件缓存的最佳实践?在将 css 附加到文档时,有没有办法可以附加 svnbuild 参数或类似的参数?
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.
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的。因此,在我发布此内容后,我深入研究了 GWT 源代码,并找到了一些有关创建 GWT 自定义链接器的链接。
http://development.lombardi.com/?p=29
http://code.google.com/webtoolkit/doc/1.6/DevGuideOrganizingProjects.html
这是我用自己的链接器解决它的方法。首先,我创建了一个扩展标准 IFrameLinker 的链接器类:
之后只需告诉您的模块使用自定义链接器即可。在你的 module.gwt.xml 文件中:
刚刚尝试了一下,现在在我的 nocache.js 文件中,每次编译时它都会输出一个新的时间戳。我的用户可以永久缓存 css 文件,每当我部署新版本的应用程序时,他们都会自动下载一个新文件。
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
Here's how I solved it with my own linker. First I made a linker class that extends the standard IFrameLinker:
After that it's just a matter of telling your module to use your custom linker. In your module.gwt.xml file:
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.
似乎现在首选的做法是使用 ClientBundles 而不是单独的 CSS:
Google Css 资源手册
。我们最近通过以下方法轻松完成了这一转变(显然有一些未来意图消除 @CssResource.NotStrict 注释):
然后在我们应用程序的根部:
这是一种严厉的方法,但它解决了问题,并且它让你走上谷歌想要的方式做事的道路。
看起来您可以相当自动地接近他们的预期方式 (虽然我还没有在 2.4 上尝试过这些,但我上面提到的东西确实可以在 2.4 下工作(我确实遇到了外部依赖项(GXT)的问题;但由于这不会改变,所以我只是使用老式的方式保留它)方法。
Seems like the preferred thing to do now is to use ClientBundles rather then separate CSS:
Google Css Resource Cookbook
. We recently made this transition quite painlessly with the following (with obviously some future intent to eliminate the @CssResource.NotStrict annotation):
Then in the root of our application:
This is kind of a heavy handed approach, but it solves the problem, and it puts you on the road to doing things the google intended way.
It looks like you can get even closer to their intended way fairly automatically (although I haven't tried these on 2.4, the stuff I mentioned above did work under 2.4 (I did have a problem with an external dependency (GXT); but since that won't change i just left it using the old fashioned method.