会员登录 | 会员注册 | 意见建议 | 网站地图

站长资源综合门户

当前位置:首页 > 站长学院 > 建站经验 > HTML5::初学者使用 Application Cache 指南

HTML5::初学者使用 Application Cache 指南

时间:2012-03-19 18:23:57   作者:   来源:   点击:

// Browser downloaded a new app cache.

// Swap it in and reload the page to get the new hotness.

window.applicationCache.swapCache();

if (confirm(‘A new version of this site is available. Load it?’)) {

window.location.reload();

}

} else {

// Manifest didn’t changed. Nothing new to server.

}

}, false);

}, false);

 

APPCACHE事件(APPCACHE EVENTS)

也许你已经想到了,还有更多事件可以反映出cache的状态。在诸如下载、app cache更新、出现错误等事件都会让浏览器触发相应事件。下面的代码片段为每一类cache event都设置了监听器:

 

function handleCacheEvent(e) {

//…

}

function handleCacheError(e) {

alert(‘Error: Cache failed to update!’);

};

// Fired after the first cache of the manifest.

appCache.addEventListener(‘cached’, handleCacheEvent, false);

// Checking for an update. Always the first event fired in the sequence.

appCache.addEventListener(‘checking’, handleCacheEvent, false);

// An update was found. The browser is fetching resources.

appCache.addEventListener(‘downloading’, handleCacheEvent, false);

// The manifest returns 404 or 410, the download failed,

// or the manifest changed while the download was in progress.

appCache.addEventListener(‘error’, handleCacheError, false);

// Fired after the first download of the manifest.

appCache.addEventListener(‘noupdate’, handleCacheEvent, false);

// Fired if the manifest file returns a 404 or 410.

// This results in the application cache being deleted.

appCache.addEventListener(‘obsolete’, handleCacheEvent, false);

// Fired for each resource listed in the manifest as it is being fetched.

appCache.addEventListener(‘progress’, handleCacheEvent, false);

// Fired when the manifest resources have been newly redownloaded.

appCache.addEventListener(‘updateready’, handleCacheEvent, false);

 

如果manifest文件或者该文件中指定的某个资源下载失败,那么整个更新都会失败。在这种情况下,浏览器会继续试用老的application cache。

分享到:

网友评论

热门建站经验