应用程序中的浏览器脚本缓存

应用程序中的浏览器脚本缓存

本文介绍了停止 GWT 应用程序中的浏览器脚本缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们客户的机器上部署了一个 GWT 应用程序.作为一个持续随着开发,我们必须发布新的改进版本不时申请.每次我们发布新版本时经常遇到客户端浏览器缓存的问题旧脚本脚本有一段时间它的行为与数据一样奇怪正在尝试与它不太兼容.是什么克服这个问题的最好方法.目前我必须告诉用户为新版本清除浏览器的缓存,但这会很好他们不必这样做.

I have a GWT app deployed onto our client's machines. As an ongoingdevelopment alongside, we have to release new improved versions of theapplication fron time to time. Everytime we release a new version weoften run into the problem where the client's browser has cached theold scripts scriptsand for a while it behaves strangly as the data itis trying to work with is not quite compatible with it. What is thebest way to overcome this problem. Currently I have to tell the usersto clear their browser's cache for a new release but it would be nicethey don't have to do this.

推荐答案

默认情况下,浏览器应缓存大部分应用,直到构建过程生成新版本.

By default, the bulk of your app should be cached by the browser until a new version of it is generated by your build process.

了解 GWT 引导模型以了解其工作原理可能会有所帮助.

It might help to understand the GWT bootstrapping model to understand how this works.

您的客户端请求的第一个脚本 your-app-name.nocache.js 没有被缓存,除了检查浏览器的用户代理和功能之外,它什么都不做,并发出第二个请求相关应用JS.

The first script your client requests, your-app-name.nocache.js, is not cached, and it does nothing except check the browser's user agent and capabilities, and make a second request for the relevant app JS.

此时,如果之前请求过,它请求的脚本应该被浏览器缓存.这是一个 {indistinguisable-numbers-and-letters}.cache.html 文件.

At this point, the script it requests should be cached by the browser if it's been requested before. This is a {indistinguisable-numbers-and-letters}.cache.html file.

当您重新部署您的应用程序时,将执行 nocache.js 文件并从服务器请求一个不同的 cache.html 文件,该文件将不存在在缓存中,但是一旦下载就会被浏览器缓存.

When you redeploy your app, the nocache.js file will be executed and ask for a different cache.html file from the server, which will not already be present in the cache, but which will get cached by the browser once it is downloaded.

您是否对延迟绑定或服务器上的缓存头做了任何异常处理?毕竟,这可能会导致您的 nocache.js 文件被缓存,这将使它从浏览器缓存中请求旧的 cache.htmls.

Are you doing anything unusual with deferred binding, or with caching headers on your server? This might potentially be causing your nocache.js file to get cached after all, which would make it request old cache.htmls from the browser cache.

这篇关于停止 GWT 应用程序中的浏览器脚本缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 15:04