我的HTML5应用程序缓存清单正在缓存所有内容 [英] My HTML5 Application Cache Manifest is caching everything

查看:181
本文介绍了我的HTML5应用程序缓存清单正在缓存所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

**我在此功能确实是新功能时发布了此问题,现在我意识到,除非通过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:
*

现在的问题是,一旦我浏览清单中没有的页面,我的实际动态php文件(如index.php),当我第一次看到该页面并且没有缓存镶边时就消失了:

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).

我也想使用这样的模式,但是再次找不到文档.为什么我的chrome appcache目录中没有显示appcache清单文件的迹象,而我去过的其他网站也没有使用过它?

谢谢您的时间!

解决方案

这是我在玩耍时发现的一个黑子:

我还没有找到最终的答案,但是据我了解,似乎清单并不一定要放在每页上.同样,我不确定,但这是我遇到的黑客.我有一个带有

的页面,例如manifest.html.

<html manifest="manifest.appcache"> 

我了解到不具有此功能的页面将不会添加到缓存中,但是如果它们在同一域中,它们仍将继续使用应用程序缓存.因此,如果您在每个页面的iframe中都包含manifest.html普通html页面,则它将不会缓存该页面,就像chrome不再输出一样:

Adding master entry to Application Cache with manifest 

但是如果进入网络"标签,您将看到它正在使用缓存

<iframe id='manifest_iframe_hack' 
  style='display: none;' 
  src='temporary_manifest_hack.html'>
</iframe> 

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>

UPDATE:

** I posted this question when this feature was really new, I realize now that this feature should not be used this way unless it is used via JavaScript. but seems like this hack is a great solution for most beginners who make the same mistake and misuse of this feature. If you want to cache everything except your HTML this should be done with JS or you could use the solution below **

I guess my question boils down to this: If the file referencing the manifest using the manifest attribute of the HTML tag falls under the MASTER CACHE ENTRIES how could you have a dynamic page use the manifest.

My file looks like this:

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:
*

Now the problem is once I browse a page not in the manifest, my actual dynamic php files like index.php, when I first see the page and there in no cache chrome goes:

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

So far so good until I actually load a page, and chrome goes:

Application Cache UpdateReady event
Adding master entry to Application Cache with manifest http://mydomain.com/manifest.appcache

now as you can see in the last line it adds index.php to my application cache and I have verified this by going to url: chrome://appcache-internals/

It says:

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

where things like index.php and home.php are not supposed to be cached. I would like to tell it to not cache any html extensions if possible. But here is what I have learned from various RFC I believe: An online whitelist wildcard flag, which is either open or blocking.

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.

well I would like to use one of these online white-list wildcard flags and set it to blocking but I can not find any explanations or examples further more. I also read:

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).

I would also like to use some pattern like this but then again I can find no documentation. Why is there no sign of appcache manifest documentation and no other website I've been to is using it , since my chrome appcache directory shows none!?!?

Thank you for your time!

解决方案

Here is a hack I found out by playing around:

I haven't found the ultimate answer but from what I've learned it seems that the manifest is not meant to be set on every page. Again I'm not sure but this is a hack that I came across. I have a page such as manifest.html that has the

<html manifest="manifest.appcache"> 

I learned that pages which do not have this will not be added to the cache however they will still continue using the application cache if on the same domain. Therfore if you include manifest.html a plain html page that has this in an iframe on everypage it will not cache that page like chrome will no longer output:

Adding master entry to Application Cache with manifest 

but if you go to network tab you will see that it is using the cache

<iframe id='manifest_iframe_hack' 
  style='display: none;' 
  src='temporary_manifest_hack.html'>
</iframe> 

content of 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>

这篇关于我的HTML5应用程序缓存清单正在缓存所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆