Application cache using HTML5

HTML5 provides an application caching mechanism that lets web-based applications run offline. Developers can use the Application Cache (AppCache) interface to specify resources that the browser should cache and make available to offline users. Applications that are cached load and work correctly even if users click the refresh button when they are offline.

Using an application cache gives an application the following benefits:

  • Offline browsing: users can navigate a site even when they are offline.
  • Speed: cached resources are local, and therefore load faster.
  • Reduced server load: the browser only downloads resources that have changed from the server.

How?

To enable application cache you must include manifest attribute in <html> tag

<html manifest=”example.appcache”>

</html>

The manifest attribute references a cache manifest file, which is a text file that lists resources (files) that the browser should cache for your application.

You should include the manifest attribute on every page of your application that you want cached. The browser does not cache pages that do not contain the manifest attribute, unless such pages are explicitly listed in the manifest file itself. You do not need to list all the pages you want cached in the manifest file, the browser implicitly adds every page that the user visits and that has the manifest attribute set to the application cache.

Advertisements