我的HTML5应用程序缓存清单正在缓存所有内容

Neo*_*Neo 23 manifest manifest.cache cache-manifest html5-appcache

更新:

**当这个功能真的很新时我发布了这个问题,我现在意识到这个功能不应该以这种方式使用,除非它是通过JavaScript使用的.但对于大多数犯错误和滥用此功能的初学者而言,这种黑客攻击似乎是一个很好的解决方案.如果你想要缓存除HTML以外的所有内容,这应该用JS完成,或者你可以使用下面的解决方案**

我想我的问题归结为:如果使用HTML标记的manifest属性引用清单的文件属于MASTER CACHE ENTRIES,那么如何使用清单来动态页面.

我的文件看起来像这样:

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:
*
Run Code Online (Sandbox Code Playgroud)

现在的问题是,一旦我浏览不在清单中的页面,我的实际动态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
Run Code Online (Sandbox Code Playgroud)

到目前为止,在我实际加载页面之前一直很好,并且chrome会:

Application Cache UpdateReady event
Adding master entry to Application Cache with manifest http://mydomain.com/manifest.appcache
Run Code Online (Sandbox Code Playgroud)

现在您可以在最后一行看到它将index.php添加到我的应用程序缓存中,并通过转到url验证了这一点: 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
Run Code Online (Sandbox Code Playgroud)

不应该缓存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.
Run Code Online (Sandbox Code Playgroud)

好吧,我想使用其中一个在线白名单通配符标志并将其设置为阻止,但我找不到任何解释或更多的例子.我也读过:

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).
Run Code Online (Sandbox Code Playgroud)

我也想使用这样的模式但是我再也找不到文档.为什么没有appcache清单文档的迹象,也没有其他网站我一直在使用它,因为我的chrome appcache目录没有显示!?!?

感谢您的时间!

Neo*_*Neo 26

这是我通过玩耍发现的黑客攻击:

我还没有找到最终的答案,但从我所学到的东西来看,似乎并不是每一页都要设置清单.我不确定,但这是我遇到的黑客攻击.我有一个像manifest.html这样的页面

<html manifest="manifest.appcache"> 
Run Code Online (Sandbox Code Playgroud)

我了解到没有这个的页面不会被添加到缓存中,但如果在同一个域上,它们仍将继续使用应用程序缓存.因此,如果您将manifest.html包含在一个简单的html页面中,该页面在每个页面上的iframe中都包含此页面,则不会像Chrome一样缓存该页面将不再输出:

Adding master entry to Application Cache with manifest 
Run Code Online (Sandbox Code Playgroud)

但是如果你进入网络标签,你会发现它正在使用缓存

<iframe id='manifest_iframe_hack' 
  style='display: none;' 
  src='temporary_manifest_hack.html'>
</iframe> 
Run Code Online (Sandbox Code Playgroud)

temporary_manifest_hack.html的内容:

<!DOCTYPE HTML>
<html lang="en" class="no-js" manifest="manifest.appcache">
    <head>
        <meta charset="utf-8">
        <title>Hack 4 Manifest</title>
    </head>
    <body></body>
</html>
Run Code Online (Sandbox Code Playgroud)

  • 是的,似乎这个实现已经改变,因为在我写这篇文章时,Chrome确实从缓存中加载了文件. (2认同)

Joe*_*hts 10

appcache始终包含html标记中包含manifest属性的页面.

如果您希望该页面本身是动态的,则必须使用对NETWORK部分中的服务的ajax调用将内容加载到其中.