javascript - html5缓存,每次用户在线时更新

标签 javascript php html caching

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/

相关文章:

javascript - 如何从嵌入式视频中获取缩略图?

javascript - 使用node.js实现简单的代理服务器

javascript - 使用 JSON 定义的函数时是否可以使用相对语法访问 JSON 属性?

javascript - 对象不支持属性或方法 'setItem'

php - APC 和 Symfony 2.1 的 app.php 应该是什么样子

php - 在 IIS7/Windows Server 2008 上安装 IonCube

javascript - 如何在 WooCommerce 3 中进行调试

javascript - 验证异常 : ExpressionAttributeValues must not be empty

java - 从html链接到jsp

html - 在 ionic 中制作一个 3 列 div 组件