离线缓存(HTML5)
Offline Caching(HTML5)
我在使用HTML 5 离线缓存方法从服务器更新缓存信息时遇到了一些困难。
这是步骤列表,
1- 创建了一个 cache.manifest 文件,其中包含以下条目
CACHE MANIFEST
# Version 1.0
CACHE:
/loading.js
/images/pan-icon.png
NETWORK:
*
然后我开玩笑地添加以下事件绑定器以从服务器加载更新的信息
window.addEventListener('load', function (e) {
window.applicationCache.update();
window.applicationCache.addEventListener('updateready', function (e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
window.applicationCache.swapCache();
console.log('Updated');
} else {
console.log('No Update');
}
}, false);
}, false);
但是总是无法从服务器获取最新的'loading.js'。我需要清除缓存才能从服务器获取更新。
有什么办法可以更新这个吗
请帮帮我
我正在使用 ASP .NET MVC 框架构建我的 Web 应用程序
当您更改清单中定义的文件的内容时,您必须同时更新清单文件,以便浏览器提取该文件的最新内容。
来自 MDN 的陷阱部分 (https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache)
When applications are cached, simply updating the resources (files) that are used in a web page is not enough to update the files that have been cached. You must update the cache manifest file itself before the browser retrieves and uses the updated files. You can do this programmatically using window.applicationCache.swapCache(), though resources that have already been loaded will not be affected. To make sure that resources are loaded from a new version of the application cache, refreshing the page is ideal.
我在使用HTML 5 离线缓存方法从服务器更新缓存信息时遇到了一些困难。
这是步骤列表,
1- 创建了一个 cache.manifest 文件,其中包含以下条目
CACHE MANIFEST
# Version 1.0
CACHE:
/loading.js
/images/pan-icon.png
NETWORK:
*
然后我开玩笑地添加以下事件绑定器以从服务器加载更新的信息
window.addEventListener('load', function (e) {
window.applicationCache.update();
window.applicationCache.addEventListener('updateready', function (e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
// Browser downloaded a new app cache.
window.applicationCache.swapCache();
console.log('Updated');
} else {
console.log('No Update');
}
}, false);
}, false);
但是总是无法从服务器获取最新的'loading.js'。我需要清除缓存才能从服务器获取更新。
有什么办法可以更新这个吗
请帮帮我
我正在使用 ASP .NET MVC 框架构建我的 Web 应用程序
当您更改清单中定义的文件的内容时,您必须同时更新清单文件,以便浏览器提取该文件的最新内容。
来自 MDN 的陷阱部分 (https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache)
When applications are cached, simply updating the resources (files) that are used in a web page is not enough to update the files that have been cached. You must update the cache manifest file itself before the browser retrieves and uses the updated files. You can do this programmatically using window.applicationCache.swapCache(), though resources that have already been loaded will not be affected. To make sure that resources are loaded from a new version of the application cache, refreshing the page is ideal.