更新:
我发布这个问题时,这个特性还很新,现在我意识到除非通过JavaScript使用,否则不应该这样使用这个特性。但是似乎这种hack对于大多数犯同样错误和误用此功能的初学者来说是一个好的解决方案。如果你想缓存除HTML以外的所有内容,应该使用JS来完成,或者你可以使用下面的解决方案。
我想我的问题归结为:如果引用使用HTML标记的manifest属性引用清单的文件属于主缓存条目,那么如何让动态页面使用该清单。
我的文件看起来像这样:
CACHE MANIFEST
CACHE:
# IMAGES:
/stylesheets/bg.jpg
/stylesheets/cont_bg.png
#and so forth..
#EXTERNAL
http://chat.mydomain.com/themes/images/panel_bg.png
http://chat.mydomain.com/themes/images/images_core.png
####################################
#STYLE SHEETS:
/stylesheets/min.css
/stylesheets/css_night.aspx
#####################################
#JAVASCRIPT:
/JAVASCRIPT/header_javascript.js
#EXTERNAL:
http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
FALLBACK:
/ /offline.php
NETWORK:
*
现在的问题是,一旦我浏览一个不在清单中的页面,我的实际动态php文件(如index.php),当我第一次看到该页面并且没有缓存时,Chrome会执行以下操作:
Adding master entry to Application Cache with manifest http://208.109.248.197/manifest.appcache
Application Cache Downloading event
Application Cache Progress event (0 of 28)
...
Application Cache Progress event (28 of 28)
Application Cache NoUpdate event
我一直顺利进行,直到我加载一个页面时,Chrome 崩溃了:
Application Cache UpdateReady event
Adding master entry to Application Cache with manifest http://mydomain.com/manifest.appcache
现在,正如您可以在最后一行中看到的那样,它将index.php添加到我的应用程序缓存中,并且我已通过访问网址:chrome://appcache-internals/
来验证这一点。
它显示:
Flags URL Size (headers and data)
Explicit, http://mydomain/JAVASCRIPT/header_javascript.js 57.5 kB
Master, http://mydomain/home.php 51.2 kB
Master, http://mydomain/index.php 53.5 kB
Master, Fallback, http://mydomain/offline.php 49.4 kB
在这里,像index.php和home.php这样的文件不应被缓存。如果可能的话,我想告诉它不要缓存任何html扩展名。但是从我所了解的各种RFC中,以下是我学到的:
一个在线的白名单通配符标志,它可以是开放的或阻止的。
The open state indicates that any URL not listed as cached is to be implicitly treated as being in the online whitelist namespaces; the blocking state indicates that URLs not listed explicitly in the manifest are to be treated as unavailable.
我想使用在线白名单通配符中的一个,并将其设置为阻止,但我找不到任何说明或示例。此外,我还阅读了:
zero or more URLs that form the online whitelist namespaces.
These are used as prefix match patterns, and declare URLs for which the user agent will ignore the application cache, instead fetching them normally (i.e. from the network or locale HTTP cache as appropriate).
我也想使用这样的一些模式,但是我发现没有任何文档。为什么没有appcache清单文档,并且我去过的其他网站都没有使用它,因为我的Chrome appcache目录中没有显示?!?
感谢您的时间!