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

发布于 2025-01-05 16:11:23 字数 2745 浏览 0 评论 0原文

更新:

** 我在这个功能还是个新功能的时候发布了这个问题,我现在意识到这个功能不应该以这种方式使用,除非它是通过 JavaScript 使用的。但对于大多数犯同样错误并滥用此功能的初学者来说,这个技巧似乎是一个很好的解决方案。如果你想缓存除 HTML 之外的所有内容,这应该使用 JS 来完成,或者你可以使用下面的解决方案 **

我想我的问题可以归结为: 如果使用 HTML 标记的清单属性引用清单的文件属于主缓存条目,那么您如何让动态页面使用清单。

我的文件看起来像这样:

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 添加到我的应用程序缓存中,并且我已通过转到 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

像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 目录没有显示任何内容!?!?

谢谢您的宝贵时间!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

守不住的情 2025-01-12 16:11:23

这是我通过尝试发现的一个技巧:

我还没有找到最终的答案,但从我所了解到的情况来看,清单似乎并不意味着在每个页面上都设置。我再次不确定,但这是我遇到的黑客攻击。我有一个诸如 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> 

内容的缓存内容:临时清单_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>

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>
梦里兽 2025-01-12 16:11:23

应用程序缓存始终包含 html 标记中包含清单属性的页面。

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

The appcache always contains the page that contains the manifest attribute in the html tag.

If you want that page itself to be dynamic, you must load content into it with an ajax call to a service that is in the NETWORK section.

泼猴你往哪里跑 2025-01-12 16:11:23

我猜 Iframe 解决方法不起作用。如果您认为文件是从应用程序缓存加载的:否。它们来自浏览器缓存。

在开发工具设置中禁用浏览器缓存并查看“网络”。您可以看到,所有元素都将通过网络加载,而不来自(应用程序)缓存。

I guess the Iframe-workaround doesn't work. If you think the files are loaeded from appcache: no. they're coming from browser cache.

disable browsercache in devtools-settings und look at "network". you can see, that all elements will be loaded via network and don't come frome (app)cache.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文