The Flow of Events

So far, I’ve talked about offline web applications, the cache manifest, and the offline application cache (“appcache”) in vague, semimagical terms. Things are downloaded, browsers make decisions, and everything “Just Works.” You know better than that, right? I mean, this is web development we’re talking about. Nothing ever “Just Works.”

First, let’s talk about the flow of events, specifically DOM events. When your browser visits a page that points to a cache manifest, it fires off a series of events on the window.applicationCache object, as I describe below. I know this looks complicated, but trust me, this is the simplest version I could come up with that didn’t leave out important information. Here’s the process:

  1. As soon as it notices a manifest attribute on the <html> element, your browser fires a checking event. (All the events listed here are fired on the window.applicationCache object.) The checking event is always fired, regardless of whether you have previously visited this page or any other page that points to the same cache manifest.

  2. If your browser has never seen this cache manifest before:

    • It will fire a downloading event, then start to download the resources listed in the cache manifest.

    • While it’s downloading, your browser will periodically fire progress events, which contain information on how many files have been downloaded already and how many files are still queued to be downloaded.

    • After all resources listed in the cache manifest ...

Get HTML5: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.