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

onupdateready

Summary

The ApplicationCache object’s cache host is associated with an application cache whose application cache group’s update status is idle, and whose application cache group is not marked as obsolete, but that application cache is not the newest cache in its group.

Property of apis/appcache/ApplicationCacheapis/appcache/ApplicationCache

Syntax

var result = window.applicationCache.onupdateready;
window.applicationCache.onupdateready = value;

Return Value

Returns an object of type nullnull

Examples

Checking fo the updateready status

// try to trigger an application cache update
window.applicationCache.update();

if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
   console.log('Cache is now ready for an update');
   // now you can call the swapCache() method to switch to the new cache
   window.applicationCache.swapCache();
}

Listening for updateready events

window.applicationCache.addEventListener('updateready',function () {
  console.log('The manifest update download has been completed successfully');
}, false);

Notes

If this event indicates that the resources have been redownloaded, the script can use swapCache to switch to the new cache. If there is more than one event, the updateready event will be the last one in the sequence. Alternatively, you could use an anonymous delegate function such as

object.onupdateready = function (e) { … }

where e is the cached event.

Related specifications

W3C ApplicationCache Specification
W3C Editor’s Draft

Attributions

  • Microsoft Developer Network: Article