Mobile Web App not clearing cache properly

后端 未结 10 721
醉酒成梦
醉酒成梦 2020-12-13 06:29

I\'ve been developing a mobile web app for iPad and I\'ve been running into an issue while testing my code.

Occasionally, and seemingly at random, the iPad will st

10条回答
  •  不思量自难忘°
    2020-12-13 06:58

    I got the solution!

    But first the problem: iPad and iPhone is not refreshing the cache when opening the app. Even deleting the app, clearing safari cache, restarting device etc. etc. doesnt work.

    And here is the solution ... taadaa !

    Your manifest-file MUST change. If it is changed, iPad/iPhone will reload the cache. So just write a version number in your manifest file and change it when you changed something:

    # Version: 1.2
    

    So a full manifest file could look like this:

    CACHE MANIFEST
    
    # Version 1.5
    
    NETWORK:
    *
    
    CACHE:
    index.html
    jquery-1.7.2.min.js
    images/logo.jpg
    

    It even reloads things like images that are not written into the manifest file. I tested it a several times.

    Btw. dont forget to check your manifest-file with http://manifest-validator.com

    My source is this very cool how to about offline web applications: http://gregsramblings.com/2012/05/28/html5-application-cache-how-to/

    It also says that you maybe need to start your app twice:

    If the manifest was updated, the browser will download all of the files in the cached file list, BUT, the original content will have already loaded at this point (remember that it’s already cached, so it loads super fast!).

    But it worked for me always on first attempt.

提交回复
热议问题