HTML Application Cache Race Condition

I’ve been noticing that when my single-page HTML5 application loads, the class I wrote to monitor the status of the application cache on page load occasionally goes out to lunch and hangs the page during bootstrapping.

The Mozilla docs on Application Cache are pretty good.

Towards the bottom is this little gem however:

You can programmatically test to see if an application has an updated cache manifest file, using JavaScript. Since a cache manifest file may have been updated before a script attaches event listeners to test for updates, scripts should always test window.applicationCache.status.

The problem with this advice is that simply reading window.applicationCache.status after registering your app cache monitoring event handlers does not provide enough context to determine what to do correctly. Here’s the dilemma:

Status == IDLE implies possible OFFLINE or NOUPDATE. If you provide custom logic for each case, the difference matters.

But you can’t know which of these might have happened unless you know if any of your event handlers are called. And of course none of them are ever called until after you return from the function that registers the handlers. So you can’t do the right thing in that function it seems.

Perhaps I missed something but it seems like you have to set a watchdog timer and check both the browser’s application cache status and the status of your event handler callbacks to determine if it’s necessary to manually invoke one of the event listener callbacks in order to get the page to bootstrap normally.


About Chris Russell
This entry was posted in Internet, Open Source, Software and tagged , , . Bookmark the permalink.

Comment on this article

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s