Dive into html5 8

You are here: Home ‣ Dive Into HTML5 ‣


Show table of contents


Hat is an offline web application? At first glance, it sounds like a contradiction in terms. Web pages are things you download and render. Downloading implies a network connection. How can you download when you’re offline? Of course, you can’t. But you can download when you’re online. And that’s how HTML5 offline applications work.

At its simplest, an offline web application is a list of URLs – HTML, CSS, JavaScript, images, or any other kind of resource. The home page of the offline web application points to this list, called a manifest file, which is just a text file located elsewhere on the web server. A web browser that implements HTML5 offline applications will read the list of URLs from the manifest file, download the resources, cache them locally, and automatically keep the local copies up to date as they change. When the time comes that you try to access the web application without a network connection, your web browser will automatically switch over to the local copies instead.

From there, most of the work is up to you, the web developer. There’s a flag in the DOM that will tell you whether you’re online or offline. There are events that fire when your offline status changes (one minute you’re offline and the next minute you’re online, or vice-versa). But that’s pretty much it. If your application creates data or saves state, it’s up to you to store that data locally while you’re offline and synchronize it with the remote server once you’re back online. In other words, HTML5 can take your web application offline. What you do once you’re there is up to you.

· 3.5+ 4.0+ 5.0+ 10.6+ 2.1+ 2.0+


An offline

web application revolves around a cache manifest file. What’s a manifest file? It’s a list of all of the resources that your web application might need to access while it’s disconnected from the network. In order to bootstrap the process of downloading and caching these resources, you need to point to the manifest file, using a manifest attribute on your element.

Your cache manifest file can be located anywhere on your web server, but it must be served with the content type text/cache-manifest. If you are running an Apache-based web server, you can probably just put an AddType directive in the. htaccess file at the root of your web directory:

AddType text/cache-manifest. manifest
Then make sure that the name of your cache manifest file ends with. manifest. If you use a different web server or a different configuration of Apache, consult your server’s documentation on controlling the Content-Type header.

☞Q: My web application spans more than one page. Do I need a manifest attribute in each page, or can I just put it in the home page?

A: Every page of your web application needs a manifest attribute that points to the cache manifest for the entire application.

OK, so every one of your HTML pages points to your cache manifest file, and your cache manifest file is being served with the proper Content-Type header. But what goes in the manifest file? This is where things get interesting.

The first line of every cache manifest file is this:

After that, all manifest files are divided into three parts: the “explicit” section, the “fallback” section, and the “online whitelist” section.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Dive into html5 8