0

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?

4

1 回答 1

1

这里可能有几种可能性:

1)你可以尝试放入“/pages/page1.htm”而不是“pages/page1.htm”

2) 还要确保所有链接和您在浏览器上键入的内容都区分大小写。('pages/page1.htm' 与 'pages/Page1.htm' 不同)

3)您提到您清除了历史记录......如果您这样做是为了测试,您也需要清除物理文件缓存,而不仅仅是历史记录。

4)这可能是最可能的原因:当您对清单文件进行更改并刷新浏览器时,会发生这种情况(假设您在线)

  • 浏览器首先加载回缓存中的所有文件
  • 然后浏览器在线检查您的清单文件
  • 它检测到清单文件已更改,然后将继续下载新文件
  • 但是,此时,您仍然会查看“旧文件”,因为浏览器在上线下载“新文件”之前已经加载了旧文件
  • 如果此时,如果您再次点击刷新(第二次),您应该获得“新文件”(并且您可以在离线后转到 page1 和 page2

这是目前的标准行为。有些人放了一些事件处理程序来提示用户进行另一次刷新(第一次刷新后)

于 2012-11-08T04:55:40.720 回答