Mobile Web App not clearing cache properly

26,436

Solution 1

For me, the solution is adding ?v=1 at the end of all your Javascript and CSS links. I've tried everything before seeing that on another Stackoverflow post and it worked directly !!! It was about time...

Solution 2

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.

Solution 3

Work around for this problem. Add a link to the Web App itself like...

<a href="javascript:top.frames.location.reload();">refresh</a>

It works just like the reload button on the iPhone/iPad Safari address bar!

Solution 4

I can't verify the cache being cleared properly but this worked for me :

In order to do this, you need to allow Web Inspector on your iOS device. Go to Settings > Safari > Advanced > Web Inspector (it has to be active) And you have to activate the developer menu on your computer's Safari. Go to Preferences > Advanced > Activate Developer menu

  1. Connect your device to your computer with the USB cable
  2. Go to safari > Developpement > Your Device name > Inspect an App (The app has to be running)
  3. This will open The inspector on your computer for the web app
  4. While the inspector is open Clear the cache (command + alt + E)
  5. With the inspector still open refresh the page on your computer (command + R)

Somehow the Webapp cache got cleared and i got the non-cached code.

Solution 5

I spent several hours trying to fix this problem, and it seems as though the manifest file that is supposed to manage file caching, can itself be cached, leaving your web-app in limbo.

In my case, I didn't want anything cached. Here's how I solved the problem:

  • Enable the mod_expires Apache module on my server
  • Create a .htaccess file in the same directory as the index file. The file should contain the line ExpiresDefault A1.

This tells the server that every file should expire one second after it was accessed. My web-app is used as a survey at student conventions, so only one person is using it at a time. My solution works for me; you might need to tweak it further so it suits you.

In the past, this problem had presented itself seemingly at random. All of my recent testing has shown it to respond as one would expect.

Share:
26,436
Mulberry
Author by

Mulberry

Updated on May 04, 2020

Comments

  • Mulberry
    Mulberry about 4 years

    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 stop properly updating all of the JS libraries I've written. After updating some code and posting the changes, I will notice some files will have properly updated while others have not. This bahavior persists after numerous cache clears, power cycles, and wifi toggles.

    If I load the app in safari i have no issues with it, but when I load from the app's homescreen icon the problem re-appears. I've done simple tests like adding an alert line to a library and that alert fires without issue anywhere except within the mobile-web-app window. Then, seemingly at random again, the problem is disappears, sometimes it takes 5 minutes, sometimes it takes an hour.

    I see this behavior regardless of whether the app is using a manifest file or not. I have also tried to flush these legacy files by updating the manifest file to force the recache that way, but the problem still persists.

    Does anyone know if this is a known issue with iPad? Is there anything on my end that can be done to address this?

  • René
    René about 12 years
    I have the same problem, but renaming the JS file didn't work for me, unfortunately. :-(
  • Anthony Graglia
    Anthony Graglia about 11 years
  • Luca Borrione
    Luca Borrione almost 11 years
    @Gunder I think you might keep on renaming it each time you have problem with a certain file .. :/
  • theflowersoftime
    theflowersoftime over 10 years
    This does not work for the main html/php file at the base of the app. Infuriating.
  • Ludovic
    Ludovic over 10 years
    You have to write them down in your manifest file like : CACHE MANIFEST #Version 3.0.10 CACHE: index.html ...
  • Aleks G
    Aleks G about 10 years
    Unfortunately, this does not seem to work if only the CSS file changed. My manifest is generated dynamically and it includes the last-modified timestamp of the latest modified file. If I look in safari on ipad, all changes are visible, however when started from the home screen, the old data is cached somewhere. Deleting the home screen app, clearing safari cache/cookies and saved websites does NOT solve the problem. When I re-add the app to home screen and start it from the icon - it still loads the old cached CSS.
  • Mike Barwick
    Mike Barwick almost 10 years
    Renaming your source files is not a good, clean, or professional way to go about it. Why don't you just use ?v=10 at the end of your file ? I.e. somescript.js?v=10. After all, this is what it's meant for...
  • frank
    frank over 9 years
    This is not enough for making the webapp upadate the cache on iOS. under Safari it works well but not when the webapp is started from the homescreen
  • chamberlainpi
    chamberlainpi almost 9 years
    Would this also work with the last version of Safari for Windows?
  • dk80
    dk80 almost 8 years
    This is the only solution that worked for me when using an AngularJS full screen web app on iPad.
  • toxaq
    toxaq over 6 years
    @bench-o validator link is broken. Can't find obvious replacement. It's also not longer clear what manifest you're talking about as manifest.json is now a thing whereas I think you're referring to Safari's appcache manifest?