Oliver Pearmain
Oliver Pearmain

Reputation: 20590

iOS6 - How to Clear Cache of Homescreen/Standalone Web App?

It would appear that Apple have changed the way homescreen/standalone web apps work in iOS 6. According to various blog posts (example) these apps now get their own dedicated space for storing their cached files, sqllite dbs, local storage etc, rather than sharing with the Safari browser like before.

Before iOS 6 when developing I used to go through the following procedure religiously to clear the cache...

  1. Remove app from homescreen.
  2. Close all pages/tabs in Safari.
  3. Finally "Clear Cookies & Data" or "Clear Data" in "Settings" > "Safari".

Unfortunately now that Apple have moved the goal posts this same procedure doesn't seem to work. After clearing, even though my changes are picked up in Safari, when I add to the homescreen and launch the app the old HTML,JS etc is still picked up.

Does anyone know how to reliably fully clear the cache in iOS 6?

Upvotes: 24

Views: 10800

Answers (9)

misha2400
misha2400

Reputation: 195

This drove me nuts for a while. Tried clearing the cache on device - no luck. Renaming the page did help, but once you rename it back, you still get the same stale version. Found the solution yesterday. You need to connect your device to Mac and open Web Inspector in Safari Develop menu. Once in Web Inspector, simply press "Reload page" button on the Inspector's toolbar and - voila - you see the fresh version on your device's screen.

Upvotes: 0

sepans
sepans

Reputation: 1372

You can connect your device and open Safari's web inspector on your computer and run document.location.reload() in the console tab to reload the page.

Before reloading you can press Option+Command+E to make sure the cache is cleared.

Instead of above you can also press Shift+Command+R to reload the page without cache but sometimes it hasn't worked for me.

Upvotes: 3

John Wolf
John Wolf

Reputation: 171

I found a a work-around. Just put a link on the web page itself for users who are having trouble seeing new version...

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

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

Upvotes: 10

SnazzyJava
SnazzyJava

Reputation: 87

Try appending a unique GET tag to the ends of any and all href attributes, for example:

<link rel="stylesheet" type="text/css" href="/css/global.css?
   <?php echo(mt_rand(10000000, 99999999)); ?>
" />

This would generate href="/css/global.css?########", with a different number nearly every time. This forces iOS' Safari to pull the "new" page down, as there is no data in its cache originating from the same URI, and there likely never will be (unless you plan on reloading the app millions of times during development :D )

Upvotes: 2

onemesh
onemesh

Reputation: 123

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.

Upvotes: 9

Jedidiah
Jedidiah

Reputation: 1194

First plug the phone into the computer then open the web app on the phone and Safari on the computer, then you can open the web inspector in Safari from the menu "Develop>Name of phone>title of app" (if you can't see the develop menu you can turn it on in Safari's preferences).

From there you can see/edit the cookies and local storage just like sites on your computer and pressing command+r while the inspector is focused will reload the app on the phone.

Upvotes: 4

laberning
laberning

Reputation: 809

If the iOS6 device has a jailbreak applied, you can use ssh to delete the content of the folder "/private/var/mobile/Library/Caches/com.apple.webapp".

Next time that you start the web app, all files will be re-downloaded from the webserver.

Upvotes: 1

Jackson Egan
Jackson Egan

Reputation: 2735

The only way to deal with this currently is to wait, but there is a workaround. If you change the name of the file, it will pull the new code. However, if you change it back to the old name before the cache clears, the old code will be used. The cache refreshes periodically and will update eventually. I just had this happen to me with a CSS file that refused to change. Time will fix it, but if you just need it to update for testing, a name change will work.

Upvotes: 0

Jack Freeman
Jack Freeman

Reputation: 1414

Just set the request you pass to the webview to NSURLRequestReloadIgnoringLocalCacheData

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; 
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];

Upvotes: -1

Related Questions