缓存清单缓存所有文件

时间:2015-01-13 14:35:12

标签: javascript html5 web-applications cache-manifest application-cache

HTML 5中的清单缓存存在问题。这是我的清单文件:

CACHE MANIFEST
# This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator
# Time: Tue Jan 13 2015 15:05:00 GMT+0100 (Central European Standard Time)

CACHE:
js/application.js
js/pdf.js
js/vendor.js
js/vendor/jquery.min.js

NETWORK:
*

SETTINGS:
prefer-online

我想在manifest.appcache中的“cache”部分中只缓存文件。浏览器不应缓存所有其他文件,如ajax请求。

现在,当我刷新网站时,每个思考都会从缓存中加载。

Cache chrome

我做错了什么?

1 个答案:

答案 0 :(得分:1)

将您的js文件放在CACHE指令之外,以显式缓存它们。

CACHE MANIFEST
# Tue Jan 13 2015 15:05:00 GMT+0100 (Central European Standard Time)

# Explicitly cached entries
js/application.js
js/pdf.js
js/vendor.js
js/vendor/jquery.min.js

# 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:
# ...

Template taken from A Beginner's Guide to Using the Application Cache

每个资源都有一个具有manifest指令的主条目:

这些是添加到缓存的资源,因为用户访问的浏览上下文包含一个文档,表明它使用其清单属性(Using the application cache)在此缓存中。

一个用于清单文件本身。

您可能会看到缓存的其他所有内容与清单文件无关,而是使用已知的缓存清除技术(例如添加到资源网址的随机参数)来暂停资源的普通浏览器缓存。

Here is a good SO post on preventing caching of ajax resources

相关问题