Html5缓存是一种将网站存储在浏览器内存中的机制,因此您可以在离线时加载它。它读取缓存 list 文件来识别哪些 URL 应该被缓存,哪些不应该被缓存。
一旦它缓存了您的网站,即使您在线,它也会永远卡住!您始终会获得网站的缓存版本。除非 list 文件内容发生更改。
问题是如何在每次用户在线时更新html5缓存?
最佳答案
缓存 list ,将在您调用时下载:
var appCache = window.applicationCache;
appCache.update(); // Attempt to update the user's cache.
...
if (appCache.status == window.applicationCache.UPDATEREADY) {
appCache.swapCache(); // The fetch was successful, swap in the new cache.
}
但是, list 文件应该更新,如果文件没有更改,则不会发生任何情况。因此,您必须生成 list 文件。并添加一些带有上次更新时间左右的评论..
CACHE MANIFEST
# 2010-06-18:v3
# Explicitly cached entries
index.html
css/style.css
# offline.html will be displayed if the user is offline
FALLBACK:
/ /offline.html
# All other resources (e.g. sites) require the user to be online.
NETWORK:
*
# Additional resources to cache
CACHE:
images/logo1.png
images/logo2.png
images/logo3.png
关于javascript - html5缓存,每次用户在线时更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32469000/