HTML and CSS Reference
In-Depth Information
applicationCache.onUpdateReady = function () {
applicationCache.swapCache();
// the cache manifest has changed, let's tell the user to
// reload to get whizz bang version 2.0
notifyUserOfUpgrade();
};
Although swapping the cache removes the old cache and loads
in the new cache, it doesn't actually swap images or reload any
of our code. This only happens if the asset is manually reloaded
or the entire window is reloaded. However, you could force a
manual reload on one of these assets by dynamically creating
a new DOM node for a script or image you wanted to reload.
For example, let's say that you have a fi le in your manifest that
has the latest version description in version.js . If the browser
has an upgrade ready (that you detected through the update
ready event), inside the notifyUserOfUpgrade function you'll load
the version.js fi fi le . L o a d fi n g t h fi s fi fi le r le - le x le c u t le s t h le J a v a S c r fi p t
that's inside the version.js fi fi le a n d y o u ' fi fi b le a b fi le t o s h o w u s le r s
the latest list of changes if they reload the application.
I think that, generally speaking, the swapCache has very limited
practical use. But the update ready event is very useful to tell
users that they might want to reload the browser to get the
updated application code, a bit like a normal desktop applica-
tion telling us there's a new upgrade ready to be downloaded.
Except in this case, the upgrade has already been downloaded
behind the scenes for us.
Using the manifest to detect connectivity
Part of HTML5 includes a property on the navigator object that
is supposed to tell you if the browser is online or offline, via
navigator.onLine
However, this property only changes via the application's menu
and toggling “Work Offline” (in Opera, IE, and Firefox). This
doesn't seem like a very good way to switch modes, so you can
use the cache manifest's FALLBACK category to detect connectiv-
ity. By including a FALLBACK rule in our manifest, you can pull in a
piece of JavaScript and detect whether you're online or offline.
 
 
Search WWH ::




Custom Search