HTML and CSS Reference
In-Depth Information
// reload to get whiz bang version 2.0
if (confirm(“Do you want to update to the latest version
¬ of this app?”)) {
// force a refresh if the user agrees
window.location.reload();
}
};
However, what if you wanted to tell the user what had changed?
Or even perhaps try to dynamically reload some portion of
the functionality. Strictly speaking, it's possible, but it might
be tricky depending on your application. Nonetheless, to load
the newly downloaded cache into memory, you can use the
applicationCache.swapCache() method:
applicationCache.onUpdateReady = function () {
applicationCache.swapCache();
// the cache manifest has changed, let's tell the user to
// reload to get whiz 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
code. This happens only 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 file 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 file. Loading this file re-executes the JavaScript
that's inside the version.js file and you'll be able to show the
user the latest list of changes if he reloads 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.
 
Search WWH ::




Custom Search