How to setup Application Cache API ("AppCache") and MIME Type for appcache.manifest

Programming, error messages and sample code
AppCache enables webpages to cache (or save) resources locally, including images, script libraries, style sheets, and so on. In addition, AppCache allows URLs to be served from cached content using standard Uniform Resource Identifier (URI) notation.

By using AppCache to save resources locally, you improve the performance of a webpage by reducing the number of requests made to the hosting server; you also enable offline access to cached resources.

To cache resources locally:

1.Create a manifest file that defines the resources you want to save.
2.Reference the manifest file in each webpage designed to use cached resources.
3.Setup text/cache-manifest MIME type for appcache.manifest

Creating a manifest file

The manifest file is a text file that defines the caching behavior for resources used by the webpage, as shown in the following example.


# Defines resources to be cached.

# Defines resources to be used if non-cached
# resources cannot be downloaded, for example
# when the browser is offline..
photos/ figure2.png

# Defines resources that will not be cached.

Declaring a manifest

To associate a manifest with a webpage, assign the name of the manifest file to the manifest attribute of the html element, as shown in the following example.

<!doctype html>
<html manifest="appcache.manifest">
  <title>A Web Page</title>
  <script src="library.js"></script>
  <link rel="stylesheet" href="stylesheet.css">
 <body onload="doSomething();">
  <p>Results go here: <span id="results">Unknown</span></p>
See more