HTML and CSS Reference
In-Depth Information
When the
update
method is called, an update to the cache is prepared. When that's ready
to download, the status of the application cache changes to
UpdateReady
. When this is set, a
call to the
swapCache
method tells the application to switch to the most recent cache.
EXAM TIP
The call to the
update
method is asynchronous. Therefore, you must handle the
onupdateready
event to determine when the update has completed the download process.
In addition to the properties and methods, the AppCache object can raise a series of
events that you can handle. The application cache typically operates in the background, and
you won't need these events. However, in some cases handling some of the events and forc-
ing an update can be useful. Table 1-16 lists the available events.
TABLE 1-16
Events available from the
applicationCache
object
Event
Description
The browser is checking for an update to the application manifest, or the
application is being cached for the first time.
onchecking
The application manifest has no update available.
onnoupdate
The browser is downloading what it has been told to do per the manifest file.
ondownloading
Files are being downloaded to the offline cache. This event fires periodically to
report progress.
onprogress
The download of the cache has completed.
oncached
The resources listed in the manifest have been newly redownloaded, and the
swapCache
method might be called.
onupdateready
A manifest file is no longer available.
onobsolete
An error has occurred. This could result from many things. Appropriate logging is
necessary to get the information and resolve.
onerror
Most of these events might not be used often, if at all. The most common scenario is to
handle the
onupdateready
method and then make a call to the
swapCache
method, as in this
example:
window.onload = function () {
var appCache = window.applicationCache;
appCache.oncached = function (e) { alert("cache successfully downloaded."); };
appCache.onupdateready = function (e) { appCache.swapCache(); };
}
Using the application cache is more about configuration than about coding. However, it's
important that you're aware the API is available for advanced scenarios where you need more
control over the process, or when you need to receive timely information about the process,
such as by handling the
onprogress
event.
Search WWH ::
Custom Search