Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

update

Summary

Invokes the application cache download process. Throws an InvalidStateError exception if there is no application cache to update. Calling this method is not usually necessary, as user agents will generally take care of updating application caches automatically. The method can be useful in situations such as long-lived applications. For example, a Web mail application might stay open in a browser tab for weeks at a time. Such an application could want to test for updates each day.

Method of apis/appcache/ApplicationCacheapis/appcache/ApplicationCache

Syntax

var result = window.applicationCache.update();

Return Value

Returns an object of type nullnull

Type: HRESULT

This method can return one of these values.

Return code/value Description
S_OK
DOMException.INVALID_STATE_ERR

11

This exception is thrown if the application cache cannot be found or the status of the cache is obsolete.

Examples

var applicationCache = window.applicationCache;



applicationCache.update();  // Attempt to update the user's cache.

if (applicationCache.status == window.applicationCache.UPDATEREADY) {

    applicationCache.swapCache();  // The fetch was successful, switch to the new cache.

        if (confirm('A new version of this site is available. Do you want to load it?')) {

            window.location.reload();

        }

}

Notes

Use this method and check the status before using swapCache.

The update method returns before the update check is complete, so it is a best practice to wait before checking the status property or calling the swapCache method.

The update method is provided for convenience, but is not necessary for basic functionality. Loading or refreshing the page is sufficient.

Related specifications

W3C ApplicationCache Specification
W3C Editor’s Draft

Attributions

  • Microsoft Developer Network: Article