2

ApplicationCache won't cache anything
index.html

<!DOCTYPE html>
<html manifest="cache.appcache">
<head>
<title>Zipcode Database</title>

File cache.appcache

CACHE MANIFEST
my.js

htacces file

AddType text/cache-manifest .appcache

When in console i run

applicationCache.update(); 

then error : InvalidStateError: Failed to execute 'update' on 'ApplicationCache': there is no application cache to update. code: 11 message: "Failed to execute 'update' on 'ApplicationCache': there is no application cache to update." name: "InvalidStateError" stack: "Error: Failed to execute 'update' on 'ApplicationCache': there is no application cache to update.↵

And applicationCache.cache =0

1
  • 1
    Did that fix it? Any update on my answer? Commented Jun 26, 2014 at 13:49

3 Answers 3

9

The manifest is perfectly fine, the different sections are purely optional.

If the status is 0, that simply means that the browser never successfully downloaded the manifest and all of it's contents. So if you want to manually run the applicationCache.update() method, make sure there is a cache at all and that it's not currently being updated, eg

status == 1 || status > 3

See http://www.html5rocks.com/en/tutorials/appcache/beginner/ for more information.

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

2 Comments

Why exclude status == 2 (applicationCache.CHECKING) ?
status == 2 is CHECKING, meaning that there might not be a cache, so you wouldn't want to swap it.
1

Your cache.appcache looks invalid, it should look like this:

CACHE MANIFEST
#v0.0.1 change this to force update

CACHE:
./my.js

if it's still not working after this, can you provide me a full HTML so I can test it more?

1 Comment

To future downvoters / question seekers: Bruno is correct, perhaps the TS had his my.js linked wrong and with my answer it did linked correctly.
0

I saw that error today in Chrome Browser. I have App Cache and Service Worker enabled in my app. So when you disable service worker it works as expected. But when you have both, Update cache event is triggered but applicationCache.swapCache(); throws that error.

so workaround is conditionally add that listener

if (!('serviceWorker' in navigator)) {
    function updateSite(event) {
       window.applicationCache.swapCache();

       if (confirm("New App Version Was Downloaded. Update now?")) {
           window.location.reload();
       }
    }

    window.applicationCache.addEventListener('updateready', updateSite, false);
}

Comments

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.