本文介绍了GWT 缓存概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能简单地向我解释一下 GWT 中缓存的概念.我在很多地方都读过这个,但可能是由于我的知识有限,我无法理解.

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.

如nocache.js、cache.js

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

推荐答案

一般来说,文件有 3 种类型 -

Generally, there are 3 type of files -

  1. 永远缓存
  2. 缓存一段时间
  3. 从不缓存

有些文件永远不会被缓存,并且总是会落入从不缓存"桶中.但是最大的性能优势来自系统地将第二个存储桶中的文件转换为可以永久缓存的文件.GWT 可以通过多种方式轻松地做到这一点.

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.

.cache.js 文件可以安全地永久缓存.如果它们发生更改,GWT 将重命名文件,因此浏览器将被迫再次下载.

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.

.nocache.js 文件不应该被缓存.即使您更改一行代码并重新编译,也会修改此文件.nocache.js 包含 .cache.js 的链接,因此浏览器始终拥有此文件的最新版本非常重要.

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.

第三个存储桶包含图像、CSS 和作为应用程序一部分的任何其他静态资源.CSS 文件总是在变化,所以你不能告诉浏览器永远缓存".但如果您使用 ClientBundle/CssResource,GWT 会为您管理文件.每次更改 CSS 时,GWT 都会重命名文件,因此浏览器将被迫再次下载.这让您可以设置强大的缓存标头以获得最佳性能.

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.

总结 -

  1. 对于与 .cache. 匹配的任何内容,设置一个远在未来的过期标头,有效地告诉浏览器将其永久缓存.
  2. 对于与 .nocache. 匹配的任何内容,设置缓存标头以强制浏览器与服务器重新验证资源.
  3. 对于其他所有内容,您应该根据更改资源的频率设置一个短的 expires 标头.
  4. 尽量使用ClientBundle/CssResource;这会自动将您的资源重命名为 *.cache 存储桶
  1. For anything that matches .cache., set a far-in-the-future expires header, effectively telling the browser to cache it forever.
  2. For anything that matches .nocache., set cache headers that force the browser to re-validate the resource with the server.
  3. For everything else, you should set a short expires header depending on how often you change resources.
  4. Try to use ClientBundle / CssResource; this automatically renames your resources to *.cache bucket

这篇关于GWT 缓存概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:31