Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my Mobile Safari cache won't clear?

I'm trying to debug a site on my iPhone4 (iOS4) iPad1 (iOS3.3) and desktop.

My problem is I cannot clear the iPhone cache at all.

If I add alerts/consoles to the js files I'm debugging, they show up on iPad and desktop, but the iPhone just keeps reloading from the cache.

If I clear the cache through settings>safari>delete browser history, cache, cookies and in Safari delete all bookmarks and remove the files on the server, iPad and desktop break (missing files) but the iPhone still loads the page as if nothing happened.

Not sure this is the right place to ask, but maybe someone else has a similar experience and an idea how to workaround?

Thanks!

EDIT:
I played around with this some more. If I start an appliction through the icon the cache seems cleared. Only when I open the page in Mobile Safari, it still uses the wrong file from cache. Pointers still welcome!

EDIT:
I'm starting a bounty on this. I'm using RequireJS and JqueryMobile on the site, so these may also be reasons for the cache not clearing. Still, I don't understand why it clears in app-mode and why it doesn't clear in Mobile Safari.

I have tried the following:
1. Clicking reload page in the URL bar does not clear the cache. Clicking on the link and then loading the page via go does seem to clear the cache once in a while

like image 789
frequent Avatar asked Aug 01 '12 07:08

frequent


4 Answers

Even though this is a bit hacky, maybe have a go at this workaround (I'm assuming this is for development)

As per the notes in disabling ajax cacheing here How to disable Ajax caching in Safari browser? you could set no-cache headers while developing or in plain HTML like this

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

obviously it won't fix your initial issue of being stuck. but you can break the cycle by adding an arbitrary query parameter ?something=3164 so the URL is effectively unique. then next time it loads hopefully it will hold onto the no-cache params.

If even that then doesnt work you could set up a bookmark which redirected you to a different random=14361 number each time to they are all effectively unique calls - but then we're getting into silly territory!

I'd like to have a proper solution but when I'm developing JS webapps I've found that sometimes everything refreshes properly for a while, then sometimes it doesnt... no real pattern i can tell - apart from the fact i think it seems to do it less when the debugger is enabled (but thats totally unsubstantiated ;-)

like image 160
joevallender Avatar answered Nov 15 '22 02:11

joevallender


When developing for iOS mobile, you can clear the cache easily by plugging the phone to a computer via USB and using the developing tools:

  1. In the phone, enable developing tools: Settings/Safari/Advanced
  2. In the computer, enable Safari develop menu: Settings/Advanced
  3. Make sure the mobile Safari is open and inspect the phone: Develop/PHONE_NAME/TAB_NAME
  4. Now you press cmd-shift-r to clear the cache in phone
like image 28
ilo Avatar answered Nov 15 '22 00:11

ilo


Try stopping safari and restart it and delete all the pages that are there in safari.... see the image how to close the pages enter image description here

like image 2
Jigar Pandya Avatar answered Nov 15 '22 01:11

Jigar Pandya


Are you dealing with an HTML5 "offline" application? The use of a manifest file for offline apps is quite new, and has strange quirks for each browser. Modify the manifest file on the server, and the iPhone should fetch the pages again.

EDIT: If you ever had a manifest file (and the HTML attribute pointing to it), if you remove the manifest in the wrong order, your cache can get tangled:

  1. HTML and manifest exist
  2. Remove the manifest file, and reload the HTML page => HTML page should un-manifest, since manifest 404's, but on some browsers it doesn't.
  3. Modify the HTML => HTML page doesn't un-cache, since the (non-existant) manifest file hasn't changed.

To correctly un-manifest it, try:

  1. Add the HTML and manifest back in
  2. Remove the HTML manifest attribute first, and reload the page
  3. Then remove the manifest file from the server.
like image 2
MidnightLightning Avatar answered Nov 15 '22 02:11

MidnightLightning