Richard
Richard

Reputation: 32909

Cache-manifest: while offline, replace all pages with a single "You are offline" page?

I'm trying to work out if something is possible with cache-manifest.

I have a mobile web app with about 5 pages. They all require connection to work in a meaningful way.

I'd like to handle gracefully the possibility that the user is offline.

So, would it be possible to use cache-manifest to replace every page on the site with another, "offline-only" page, while the user is offline?

I was hoping this was what the FALLBACK section of cache-manifest does, but it seems not.

Upvotes: 0

Views: 461

Answers (1)

robertc
robertc

Reputation: 75707

It does work, your fallback section should look like this:

FALLBACK:
/ offline.html

If you reference that from a page in the root then any random string you type in will result in offline.html being loaded, including pages which don't exist, whether the server is online or not.

I'm guessing that the issue you're seeing is that any page which references the manifest is always cached. So if you've referenced the manifest file from each of your five pages then all of those pages will be in the Application Cache.

One approach which might work (I've not tried it): create a new page specifically to reference the manifest file and redirect your users to it when they first visit. You could put some content on the page like 'initializing application'. Verify the Application Cache has been loaded with JavaScript, then redirect back to the page they came from.

Upvotes: 1

Related Questions