How to use network version when available with HTML5 manifest
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 w开发者_StackOverflowhen possible. Currently, the cached versions are being loaded even when the network is available.
Add this to the header:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
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.
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.
精彩评论