Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

608 CHAPTER 16 Offline web applications


Browser support


The application cache is now supported in the latest version of all major browsers. Internet
Explorer is the latest to add support with the release of Internet Explorer 10. It’s also sup-
ported in most mobile browsers, which can make it very useful when cellular data services
aren’t available.

The cache manifest file


The application cache hinges on the existence of a manifest file in your web application. The
key to being served correctly is to use the text/cache-manifest content type in the HTTP
response. The file itself can reside anywhere on your web server, such as /home/manifest” or
“/manifest.appcache. If you choose to use a static file reference, you might need to configure
the MIME type in Internet Information Server (IIS) first or add a mimeMap element to your
application’s web.config file as follows.
<system.webServer>
<staticContent>
<mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
</staticContent>
</system.webServer>

To include the manifest file in your application, it must be referenced by using the manifest
attribute on the page’s <html> element as follows.
<!DOCTYPE html>
<html manifest="manifest.appcache ">

This example references the manifest file by using a relative URL, but you can use an abso-
lute URL as long as it’s part of the same origin, as follows.
<html manifest="http://www.example.com/manifest.appcache ">

Understanding structure
You’ve learned how to reference a manifest file and that it must be served with the text/
cache-manifest content type. The following is what a sample manifest file looks like.
CACHE MANIFEST
# version 1.0

# Explicit cache declarations
CACHE:
/Content/Styles/Site.css
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js

# The following should not be cached
NETWORK:
/Login/
/API/

# Alternative files
Free download pdf