Tuesday, 15 January 2013

javascript - prevent ajax call if application cache is being updated -



javascript - prevent ajax call if application cache is being updated -

i writing offline web application.

i have manifest files applicationcache. , have handlers appcache events. want observe if files beingness downloaded beingness downloaded first time or beingness updated. because in case beingness updated, prevent application code running, since refresh browser after updating app.

my specific problem here when "checking" events gets fired, applicationcache status "downloading",

does know how applicationcache.status before manifest or files gets downloaded?

thanks in advance answer

window.applicationcache.addeventlistener('checking', function (event) { console.log("checking updates."); console.log("inside checking event, appcache status : %s", applicationcache.status); }, false); window.applicationcache.addeventlistener('updateready', function (e) { if (window.applicationcache.status == window.applicationcache.updateready) { // browser downloaded new version of manifest files window.location.reload(); } }, false); window.applicationcache.addeventlistener('downloading', function (event) { appcommon.information("new version available", "updating application files...", null, null); }, false); window.applicationcache.addeventlistener('progress', function (event) { $("#informationmodal").find(".modal-body").html("updating application files... " + event.loaded.tostring() + " of " + event.total.tostring()); }, false); window.applicationcache.addeventlistener('cached', function (event) { $("#informationmodal").find(".modal-body").html("application date."); settimeout(function () { $("#informationmodal").find(".close").click(); }, 1000); }, false);

according specification checking event first event.

the user agent checking update, or attempting download manifest first time. this first event in sequence.

i think error refresh browser since not automatically fetch new copy. if @ mdn guide using applicationcache you'll see files loaded applicationcache first , proceed go through cycle of events attempted avoid refreshing.

instead of refreshing should create proper utilize of applicationcache event life cycle in order initialize , start application.

i prevent application code running, since refresh browser after updating app.

you have lot of command of when application begins run, if wanted refresh browser, start app after updateready or noupdate events, instead of refreshing seems should utilize window.applicationcache.swapcache instead.

i found question , answer useful.

javascript ajax manifest application-cache

No comments:

Post a Comment