Using the application cache it can be very easy to create an offline version of a web application, by creation of a cache manifest file.
What is Application Cache?
HTML5 has introduced application cache, which enables a web application to be cached, and accessible without having an internet connection.
Application cache can giva an application these three advantages:
The table numbers specify the version of thefirst browser which was completely supporting Application Cache.
HTML Cache Manifest Example
The example below illustrates how an HTML document with a cache will manifest (for offline browsing):
Cache Manifest Basics
Inorder to enable application cache, inclusion of the manifest attribute in the document's <html> tag:
Every page having the manifest attribute specified will undergo cached when the user is visiting it. Incase the manifest attribute is not specified, the page will not undergo cache (unless and until the page gets specified inside the manifest file directly).
The file extension that is recommended for manifest files is: ".appcache"
A manifest file should be served with the correct media type, that is "text/cache-manifest". It should be configured on the web server.
The Manifest File
The manifest file can be known as a simple text file, which instructs the browser what to cache (and what not to cache).
The manifest file consists of three sections:
The first line - CACHE MANIFEST, is needed:
The NETWORK section as shown below illustrates that the file "login.asp" should not be cached, and is not available offline too:
An asterisk is used to denote that all other resources/files will be requiring an internet connection:
The FALLBACK section below is specifying that "offline.html" will be availalbe as a replacement of all files in the /html/ catalog, if internet connection is lost:
Note: The first URL is known as the resource, the second is known as the fallback
Updating the Cache
If an application is cached, it will remain to be cached till any one of the following is happening:
Example - Complete Cache Manifest File
Notes on Application Cache
You need to be careful while deciding what you cache.
If a file is cached, the browser will be showing the cached version, even if you are changing the file on the server. To make sure the browser is updating the cache, you must be changing the manifest file.
Note: Different browsers will be having different size limits for these cached data (some of the browsers have for eg - a 5MB limit per site).