HTML5 离线奇怪行为
我正在开发的网络应用程序遇到问题,我发布了一个问题 这里有点模糊,可能不是很有帮助。我决定创建一个非常基本的网站,并将其构建为类似于主应用程序,然后看看它在哪里出现问题。我已经这样做了,但立即陷入了离线缓存的困境。
这是一个在 IIS 7.5 本地托管的基本 3 页静态网站。我创建了文件夹 c:\inetpub\wwwroot\ManifestTesting,将其作为 Web 应用程序添加到 IIS,并为 .appcache 扩展添加了新的 MIME 类型 text/cache-manifest。我还使用 FireFox 9.0 进行测试,因为它具有离线模式功能。
我创建了 3 个 html 页面并将它们添加到 ManifestTesting 文件夹中:
- index.htm - 此页面包含 2 个指向 page1.htm 和 page2.htm 的链接
- page1.htm - 仅包含一个标头,显示第 1 页
- page2.htm - 仅包含一个标头上面写着第 2 页
所以现在如果我浏览到 http://localhost/manifesttesting 如果获取索引页面并可以导航到这 2 个页面。
然后,我创建了一个名为 manifest.appcache 的文件,并将其添加到 ManifestTesting 文件夹中:
CACHE MANIFEST
CACHE:
index.htm
page1.htm
page2.htm
并在 index.htm 中添加了对清单文件的引用:
<html manifest="manifest.appcache">
因此,如果我清除所有历史记录并浏览到 index.htm,FireFox 会询问我是否想要允许网站存储数据以供离线使用。我单击允许,将浏览器切换到离线模式,然后尝试导航到 page1.htm ,效果很好!所以到目前为止一切都很好。
现在来说说我不明白的地方。然后,我在 ManifestTesting 文件夹中创建了一个名为“pages”的新文件夹,并将 page1 和 page2 移入其中。我更新了索引中的链接以引用新位置,如果我在没有清单引用的情况下浏览网站,一切都会像以前一样正常工作。然后我重新引用索引中的清单文件并将清单更新为:
CACHE MANIFEST
CACHE:
index.htm
pages/page1.htm
pages/page2.htm
然后我清除历史记录,刷新,firefox 要求允许网站存储离线数据,启用离线模式,然后尝试导航到 page1 - 它没有不行! FireFox 告诉我它处于离线模式并且无法浏览网页!
我做错了什么?
I am having a problem with a web app that I'm working on and I have posted a question here which is a bit vague and probably not very helpful. I have decided to create a really basic site and build it up to be like the main app and see where it breaks. I have done this and got stuck straight away with the offline caching.
This is a basic 3 page static website hosted locally in IIS 7.5. I created the folder c:\inetpub\wwwroot\ManifestTesting, added it to IIS as a web application and added a new MIME type of text/cache-manifest for the .appcache extension. I am also using FireFox 9.0 for testing as this has an offline mode feature.
I created 3 html pages and added them to the ManifestTesting folder:
- index.htm - this page contains 2 links to page1.htm and page2.htm
- page1.htm - just contains a header that says page 1
- page2.htm - just contains a header that says page 2
So now if I browse to http://localhost/manifesttesting if get the index page and can navigate to the 2 pages.
I then created a file called manifest.appcache and added it to the ManifestTesting folder:
CACHE MANIFEST
CACHE:
index.htm
page1.htm
page2.htm
and added the reference to the manifest file in the index.htm:
<html manifest="manifest.appcache">
So if I clear all history and browse to the index.htm, FireFox asks if I want to allow the website to store data for offline use. I click allow, switch the browser to offline mode then attempt to navigate to page1.htm which works fine! So all is good so far.
Now for the bit that I don't understand. I then created a new folder in the ManifestTesting folder called 'pages' and moved page1 and page2 into it. I updated the links in the index to reference the new location and if I browse the website without the manifest reference, it all works fine just as before. I then re-reference the manifest file in the index and update the manifest to be like:
CACHE MANIFEST
CACHE:
index.htm
pages/page1.htm
pages/page2.htm
I then clear history, refresh, firefox asks to allow the website to store offline data, enable offline mode and then attempt to navigate to page1 - it doesn't work! FireFox tells me it's in offline mode and can't browse the web!
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里可能有几种可能性:
1)您可以尝试输入“/pages/page1.htm”而不是“pages/page1.htm”
2)还要确保所有链接和您在浏览器上键入的内容都是大小写-敏感的。 ('pages/page1.htm' 与 'pages/Page1.htm' 不同)
3)您提到您清除了历史记录...如果您这样做进行测试,则需要清除历史记录物理文件也会缓存,而不仅仅是历史记录。
4)这可能是最可能的原因:当您对清单文件进行更改并刷新浏览器时,会发生这种情况(假设您在线)
再次(第二次),您应该获得“新文件”(并且您可以在离线后转到 page1 和 page2
这是目前的标准行为。有些人放置了一些事件处理程序来提示用户执行另一个操作刷新(第一次刷新后)
There could be a few possibilities here :
1) Can you try putting in "/pages/page1.htm" instead of "pages/page1.htm"
2) also make sure that all the link and what you type on the browser is Case-Sensitive. ('pages/page1.htm' is not the same as 'pages/Page1.htm')
3) you mentioned that you cleared the history... if you're doing it this way for testing, you need to be clearing the physical files cache too, not just the history.
4) this is probably the most likely cause : when you made changes to the manifest file, and you refresh the browser, this is what happens (assuming you're online)
again (2nd time), you should get the 'new files' (and you would be able to go to the page1 and page2 after going offline
This is currently the standard behaviour. Some people put some event handlers to prompt the user to do another refresh (after the 1st refresh)