1

So I've got an application that stores offline data using an ApplicationCache. Long story short, it's silently dying for users who don't have offline data enabled, most commonly because they've got history turned off or are using private browsing, and I'd like to catch this and give the user a clear error.

It appears that this can be detected by checking the cache's state, which will return 0 UNCACHED when there is no cache... but I'm not sure if that means that there is no cache yet, or that there's no cache guaranteed (and because there should be, something's wrong). The official definition is less than useful:

UNCACHED (numeric value 0)
The ApplicationCache object's cache host is not associated with an application
cache at this time.

In practice, though, aborting on cache.status==0 seems to work fine at least on Firefox. Am I doing it right, or is there a better way? Extra points if somebody can dig up a state diagram.

Update: Nope, it also returns 0/UNCACHED if the user has never been to that page before. Gar!

1 Answer 1

2

Listen for the error event on applicationCache. When this fires and applicationCache.status===applicationCache.UNCACHED, one reason among many is that caching is disabled. The message to the user may suggest that caching is turned off.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, could this also indicate that applicationCache isn't supported on the device / browser in question? or would the window.applicationCache property just not exist at all in this case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.