I have a multi-page website. I want to make two of those pages available offline, using the HTML5 manifest. However, I want the online counterparts to be used instead of the local cached version when possible. Currently, the cached versions are being loaded even when the network is available.
-
This question seems related: http://stackoverflow.com/questions/1715568/how-to-properly-invalidate-an-html5-cache-manifest-for-online-offline-web-apps. However, I don't want to invalidate it every time I make a change. – Chris Laplante Jun 27 '11 at 15:37
3 Answers
Add this to the header:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

- 14,124
- 18
- 66
- 103
-
It's still loading the document from the manifest. Note that I'm referring to the HTML5 manifest; not just the browser cache. – Chris Laplante Jun 27 '11 at 15:31
-
It is a valid manifest, with CACHE MANIFEST at the top, a CACHE section, and a listing of my two pages and the images, CSS, and javascript they use. Nothing special – Chris Laplante Jun 27 '11 at 20:57
If you want certain pages to always load from the server when on-line, the implication is that they are in some way more up-to-date?
If that's the case, you need to ensure that your site's off-line cache recognises that these elements have changed, and thus update them instead. I guess the only way is to force this refresh by ensuring that when the relevant elements are updated on the server, so is your off-line cache manifest file.
(You can of course use the NETWORK
directive in your cache manifest to compel the user agent to always go to the server for certain resources but then as you imply, you won't have these pages available when off-line).
So you don't have to necessarily invalidate the cache file, but you do need to ensure that it triggers an update and cache-swap.

- 7,548
- 31
- 45
-
When served over a network, the pages will include dynamic content. When served from the cache manifest, this will not be true. So, when the browser is connected, it should always fetch the version from my webserver since this will include the dynamic content. – Chris Laplante Jun 27 '11 at 21:01
The solution I found was to ensure that the pages I cache in the manifest do not contain any dynamically generated content. When online, my JavaScript code performs an Ajax request to fetch the dynamically generated content. The JavaScript detects when the browser is offline and will refuse to perform the Ajax requests, essentially shifting into offline-only mode.

- 29,338
- 17
- 103
- 134