强制applicationCache重新加载缓存的文件 [英] Force applicationCache to reload cached files

查看:159
本文介绍了强制applicationCache重新加载缓存的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HTML5 applicationCache来存储页面的许多Javascript,CSS,图像等文件。如果我更新其中一个文件,浏览器永远不会重新加载它。我尝试过以下方法:

I'm using the HTML5 applicationCache to store many Javascript, CSS, image, etc. files for a page. If I update one of those files, the browser never reloads it. I have tried the following:


  • 在页面加载时调用applicationCache.update()

  • 正在收听applicationCache的updateready事件,并调用swapCache()和window.location.reload()

  • 向清单文件本身添加时间戳注释以强制浏览器实现清单已更改

当然这不是很难。如何说服浏览器重新请求某些缓存文件?

Surely this can't be this hard. How do I convince the browser to re-request some cached file?

推荐答案

强制任何新的(或更改的)文件下载后,您必须更新清单文件(添加版本号注释或任何更改都可以)。
可能发生的是你收到错误。最常见的一种是您可能没有使用正确的mime类型( text / cache-manifest )提供清单。您是否正确配置了服务器?检查此问题的最简单方法是在Chrome中打开该页面,然后在AppCache下的控制台和资源选项卡中查看是否存在错误(它会报告错误地提供文件。您也可以使用curl -I命令:

To force any new (or changed) file to be downloaded, you must update the manifest file (add a version number comment or any change will do). What's probably happening is that you're getting an error. The most common one is that you might not be serving the manifest with the right mime type (text/cache-manifest). Did you configure your server correctly? The easiest way to check this is to open the page in Chrome and look in the console and the resources tab under AppCache to see if there is an error (it will complain about the file being served up incorrectly. You can also test it with the curl -I command:

curl -I $manifest_file_URL

您的清单文件也可能被缓存(您可以设置它的expires头文件立即过期)。还要记住重新加载序列:您的页面将加载首先从AppCache(如果有),然后浏览器检查清单文件是否更新。如果是,请下载并放入新版本的缓存中,但这不会自动更新页面(也不会 swapCache()),你必须再次刷新页面(至少)。

It is also possible that your manifest file is getting cached (you can set the expires headers for it to expire rightaway). Also keep the reloading sequence in mind: your page will load from AppCache first (if it is there), then the browser checks if the manifest file is updated. If it is, download and place in the new version of the cache, but this will not automatically update the page (nor will swapCache()), you will have to refresh the page (at least) once more.

参见 thi有关该主题的更多信息,请参阅演示文稿

这篇关于强制applicationCache重新加载缓存的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆