Question

is it possible to modify the local app cache in the client side using JavaScript ? i need to update the app cache each time the client view or add a new item. EDIT for example this is my appcache file :

 CACHE MANIFEST
 # 2014-02-13 v13.0.0

CACHE:
#HTML
http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js
animation.js
test.css

the question is if there is a ways to update the manifest and add a new line to it in order to add a new file to store without the intervention of the server side to be like this :

CACHE MANIFEST
     # 2014-02-13 v13.0.0

    CACHE:
    #HTML
    http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js
    animation.js
    test.css
    http://download.support.xerox.com/pub/docs/FlowPort2/userdocs/any-os/en/fp_dc_setup_guide.pdf
Was it helpful?

Solution

What you want to do can be done, sort of. The main caveat is that each time you update your cache, it will redownload the whole lot rather than just the new files you have added.

The code to force the browser to read the new appcache file is pretty simple:

function updateCache(){ 
    var appCache = window.applicationCache;

    appCache.update(); 

    if (appCache.status == window.applicationCache.UPDATEREADY) {
        appCache.swapCache(); 
    }
}

I suggest having a read of http://www.html5rocks.com/en/tutorials/appcache/beginner/ and http://appcachefacts.info/ for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top