简体   繁体   中英

html5 appcache adding/removing specific files

Say I have a simple appcache manifest that looks like:

CACHE:
# v1
# images
images/one.jpg
images/two.jpg
images/three.jpg

I then use some server side method to update the manifest to:

CACHE:
# v1
# images
images/one.jpg
images/two.jpg
images/three.jpg
images/four.jpg

And then call a function client side to update the appcache:

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

    appCache.update(); 

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

I would like to 'add' my new image to the existing cache without downloading everything again (which is what's currently happening). Is this possible or am I missing something fundamental?

It will download everything again, that's the way it's designed to work. However if you have set far future expiry headers on your images then the chances are the browser will fetch them from the local browser cache rather than requesting them off the server again.

Note that if you do this during development this can lead to some strange behaviour, but you should definitely do it for production sites.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM