GWT 缓存概念
有人可以简单地向我解释 GWT 中缓存的概念吗?我在很多地方都读过这篇文章,但可能由于我的知识有限,我无法理解它。
例如 nocache.js、cache.js
或其他东西,例如使客户端永久缓存文件或如何使客户端缓存文件,然后如果文件在服务器上发生更改,客户端才会再次下载这些文件
Can someone explain to me in simple term the concept of caching in GWT. I have read this in many places but may be due to my limited knowledge, i'm not being able to understand it.
Such as nocache.js, cache.js
or other things such as making the client cache files forever or how to make files cached by the client and then if file get changed on the server only then the client download these files again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,有 3 种类型的文件 -
某些文件永远不会被缓存,并且将始终落入“从不缓存”存储桶中。但最大的性能优势来自于系统地将第二个存储桶中的文件转换为可以永久缓存的文件。 GWT 可以通过多种方式轻松实现这一点。
.cache.js
文件可以安全地永久缓存。如果它们发生变化,GWT 将重命名该文件,因此浏览器将被迫再次下载它。.nocache.js
文件永远不应该被缓存。即使您更改一行代码并重新编译,该文件也会被修改。 nocache.js 包含.cache.js
的链接,因此浏览器始终拥有该文件的最新版本非常重要。第三个存储桶包含图像、CSS 和属于应用程序一部分的任何其他静态资源。 CSS 文件总是在变化,所以你不能告诉浏览器“永远缓存”。但如果您使用 ClientBundle / CssResource,GWT 将为您管理该文件。每次更改 CSS 时,GWT 都会重命名该文件,因此浏览器将被迫再次下载它。这使您可以设置强大的缓存标头以获得最佳性能。
总之 -
Generally, there are 3 type of files -
Some files can never be cached, and will always fall in the "never cache" bucket. But the biggest performance wins comes from systematically converting files in the second bucket to files that can be cached forever. GWT makes it easy to do this in various ways.
The
<md5>.cache.js
files are safe to cache forever. If they ever change, GWT will rename the file, and so the browser will be forced to download it again.The
.nocache.js
file should never be cached. This file is modified even if you change a single line of code and recompile. The nocache.js contains the links of the<md5>.cache.js
, and therefore it is important that the browser always has the latest version of this file.The third bucket contains images, css and any other static resources that are part of your application. CSS files are always changing, so you cannot tell the browser 'cache forever'. But if you use ClientBundle / CssResource, GWT will manage the file for you. Every time you change the CSS, GWT will rename the file, and therefore the browser will be forced to download it again. This lets you set strong cache headers to get the best performance.
In summary -
这篇博文很好地概述了 GWT 引导过程(以及 GWT 的许多其他部分)顺便说一下,系统),这与缓存的内容和原因有很大关系。
基本上,生成的 nocache.js 文件是一段相对较小的 JS,其唯一目的是决定应该下载哪个生成的排列。
每个单独的排列都包含特定于用户的浏览器、语言等的应用程序的实现。这比简单的引导代码要多得多,因此需要缓存以便您的应用程序快速响应。这些是 GWT 编译器生成的 cache.html 文件。
当您重新编译和部署应用程序时,您的用户将照常下载 nocache.js 文件,但这将告诉他们的浏览器下载包含应用程序新功能的新 cache.html 文件。现在,这也将被缓存,以供下次加载您的应用程序时使用。
This blog post has a good overview of the GWT bootstrapping process (and many other parts of the GWT system, incidentally), which has a lot to do with what gets cached and why.
Basically, the generated nocache.js file is a relatively small bit of JS whose sole purpose is to decide which generated permutation should be downloded.
Each individual permutation consists of the implementation of your app specific to the browser, language, etc., of the user. This is a lot more code than the simple bootstrapping code, and thus needs to be cached for your app to respond quickly. These are the cache.html files that get generated by the GWT compiler.
When you recompile and deploy your app, your users will download the nocache.js file as normal, but this will tell their browsers to download a new cache.html file with the app's new features. This will now be cached as well for the next time they load your app.