Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 AppCache: how to implement offline mode if server isn't accessible but network is accessible

By design HTML5 Offline support (AppCache) works if client device is offline or client device is online and server is accessible. After that I cached the application and reopened it in the browser (of refresh it) when the device has no internet access the browser loads the application from AppCache. In this case the browser does not try to fetch appcache manifest (it understand that we're offline).

But let's consider a case when my device is not offline. It still has internet connection. But my server is down. There could be many different reasons for this (hardware failture, AppPool stopped, IIS throttling, DNS error and so on). In this case when I open a cached application in the browser it'll try to fetch appcache manifest and gets 404 error (not found). And after that the browser clears AppCache for the app! So on the next run it won't load it from AppCache and show 404 error "page". No more offline work.

It looks strange for me that offline mode functioning depends on a reason the server isn't accessible. Why should I care as a user (it's no internet connection or server is down)?

So my question is: do anybody know any way to make an application work when a device is online but its server isn't reachable?
Ideally I should be able to catch window.applicationCache's error event and tell it "it's ok, please continute to use the cache, do not obsolete it".

like image 270
Shrike Avatar asked Jan 24 '13 16:01

Shrike


People also ask

What allows html5 application to work in an offline state?

Offline web applications are available through the new HTML Offline Web Application API, also known as HTML Application Cache. Beyond simply serving pages to the user when an Internet connection is unavailable, often an offline application requires storage of user's information.

Which of the following is not a valid section of AppCache manifest?

Which is not the section of manifest? Explanation: If the files are not in cache they come from a list of the files in the network. Cache is the default section.


1 Answers

This is not possible per the application-cache specification:

Otherwise, if fetching the manifest fails in some other way (e.g. the server returns another 4xx or 5xx response or equivalent, or there is a DNS error, or the connection times out, or the user cancels the download, or the parser for manifests fails when checking the magic signature), or if the server returned a redirect, or if the resource is labeled with a MIME type other than text/cache-manifest, then run the cache failure steps.

like image 113
Mike Nitchie Avatar answered Oct 05 '22 23:10

Mike Nitchie