HTML5 - 缓存清单在Chrome上运行良好,但不在Firefox和Opera上运行 [英] HTML5 - cache manifest working great on Chrome but not on Firefox and Opera

查看:158
本文介绍了HTML5 - 缓存清单在Chrome上运行良好,但不在Firefox和Opera上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Chrome(15.0.874.106)上一切正常,但却是在Firefox(7.0.1)和Opera(11.52)上不起作用。
$ b

这是我的缓存清单文件 cache.manifest.php (我已经减少到最低限度):

 <?php 
header (Cache-Control:max-age = 0,no-cache,no-store,must-revalidate);
header(Pragma:no-cache);
标题(到期日:星期三,1984年1月11日05:00:00 GMT);
header('Content-type:text / cache-manifest');
> CACHE MANIFEST

CACHE:

/app/common/css/reset.css
/favicon.ico

这是mainHTML文档的前4行:

 <!DOCTYPE html> 
< html manifest =/ app / mobile / cache.manifest.php>
< head>
< title> MyApp Mobile< / title>

当我尝试加载缓存清单(http://www.myapp.com/app/ mobile / cache.manifest.php)到浏览器文件显示正确,但是当我尝试加载页面一旦离线我得到无法连接的错误页面。再次,这只发生在Firefox和Opera上。

Firebug说:离线缓存中有0个项目,我没有找到检查应用程序缓存的方法在DragonFly上。

我正在生气,我不知道如何在Firefox和Opera上有效地调试问题。
请帮助。

谢谢,
Dan

解决方案

根据我的经验,使用HTML5 AppCache,一旦你使用它,它是非常棒的,但是非常脆弱。如果最麻烦的事情是浏览器忽略整个文件,烦恼的是,而不是使用浏览器的普通缓存,重新加载从服务器的一切从头开始。



更糟的是,浏览器不会重新加载清单文件,除非其文本内容发生更改。所以你可以调整你的服务器头文件或修改它,但是除非 cache.manifest.php 改变,否则浏览器会盲目地忽略它并且正确地做它上次做的 。所以它可能已经被破坏,然后你修正了它,但是浏览器忽略了这些改变,因为 cache.manifest.php 的文本内容没有改变。这甚至似乎免疫清除您的浏览器缓存,这是令人困惑的一部分 - 应用程序缓存是真正的,真正的缓存。



这个,注释中的文本变化会被计数,所以在上面注释一个版本或时间戳或者日期(例如#版本1.2 ),并且当你想要浏览器到通知。

然后,浏览器仍然不会马上使用它!应用程序缓存的工作方式是下一次加载页面时,它将再次执行上一次完成的操作,然后开始检查后台的更新。所以你可能需要控制台,等待更新...,然后完成,然后点击刷新,浏览器将最终开始使用新版本。最后!

总而言之,这可能是一个正确的工作。但是,一旦它正常工作,它几乎是无懈可击的:几乎所有的时间,每个用户,每个用户,每个用户,每个用户,每个用户,每个用户,每个用户,每个用户,每个用户,每个用户 直到您更改文件的文本内容为止。



浏览器标准符合性现在相当不错,所以我最好的猜测是您确实有效,但您最后检查了Chrome它是唯一正确缓存清单文件的浏览器。在开发过程中你可能已经崩溃了,但是Firefox和Opera正在抓住他们的旧清单文件到死亡。我敢打赌,你也尝试清除Firefox和Opera中的浏览器缓存,这可能什么都不做 - 你需要改变文件的文本内容,并在Firefox和Opera最终放弃它们的清单文件的破碎版本之前进行双刷新,开始使用您可能在几年前上传的作品。


I am developing a web app for offline use, thus I need to use the application cache functionality.

Everything works great on Chrome (15.0.874.106) but is doesn't work on Firefox (7.0.1) and Opera (11.52).

This is my cache manifest file cache.manifest.php (I have reduced it to the bare minimum):

<?php 
    header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
    header("Pragma: no-cache");
    header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
    header('Content-type: text/cache-manifest');
?>CACHE MANIFEST

CACHE:

/app/common/css/reset.css
/favicon.ico

And this is the first 4 lines of the "main" HTML document:

<!DOCTYPE html> 
<html manifest="/app/mobile/cache.manifest.php"> 
    <head> 
    <title>MyApp Mobile</title> 

When I try and load the cache manifest (http://www.myapp.com/app/mobile/cache.manifest.php) into the browser the file is displayed correctly but when I try to load the page once offline I get the "Unable to connect" error page. Again, that just happens on Firefox and Opera.

Firebug says "0 items in offline cache" and I didn't find the way to check the application cache on DragonFly.

I am getting mad and I don't know how to debug the problem effectively on Firefox and Opera. Please help.

Thanks, Dan

解决方案

In my experience using the HTML5 AppCache, it is great once you get it working, but extremely brittle. If there's the tiniest thing wrong with it the browser ignores the entire file and, annoyingly, rather than use the browser's ordinary cache, re-loads everything from scratch off the server.

Worse, browsers will not re-load the manifest file unless its text content changes. So you might tweak your server headers or something to fix it, but unless the content of cache.manifest.php changes the browser will blindly ignore it and do exactly what it did last time. So it could have been broken, then you fixed it, but browsers are ignoring the changes because the text content of cache.manifest.php hasn't changed. This even seems to be immune to clearing your browser cache, which is part of what makes it so confusing - app cache is really, really serious about caching.

To get around this, text changes in comments count, so have a comment at the top with a version or timestamp or the date (e.g. # Version 1.2) and change that when you want the browser to "notice".

Then, the browser still won't immediately use it! The way the app cache works is the next time you load the page it will do exactly what it did last time yet again, and start checking for an update in the background. So you probably want the console up, wait for something like "updating..." then "complete", then hit Refresh and the browser will finally start using the new version. At last!

All in all it can be a right pain to get working. However, once it's working it's almost bulletproof: you can pretty much rest assured anything listed in the cache manifest is only every downloaded once, ever, for all time, per user, until you change the text content of the file.

Browser standards compliance is pretty good these days, so my best guess is you actually have it working, but you checked Chrome last and it's the only browser which has cached the manifest file correctly. During development you might have had it broken, but Firefox and Opera are clutching their old manifest files to the death. I bet you also tried clearing the browser cache in Firefox and Opera, which probably did nothing - you need to change the text content of the file and double-refresh before either Firefox and Opera will finally give up their broken versions of the manifest file and start using the one which works which you probably uploaded ages ago.

这篇关于HTML5 - 缓存清单在Chrome上运行良好,但不在Firefox和Opera上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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