19

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

frequent
  • 27,643
  • 59
  • 181
  • 333
  • I have yet to really play with a Cache Manifest, but can you use the `NETWORK` section of a Cache Manifest to specify that your files should be refreshed each page load? Or what about appending timestamps to the URL of assets you want to make sure are not cached? Or perhaps you can set a `Cache-Control: no-cache, must-revalidate` header for the assets you want to not be cached? An `Expires` header set to the past is another one to try. Mind if I ask what specific files you don't want cached? – Jasper Aug 10 '12 at 01:28
  • 1
    Did you try clearing the cache in Settings, then pressing and holding the Sleep/Wake and Home buttons (to hard shut down your iPhone)? When I did this and then restarted the iPhone, finally, the cache was refreshed. – Jared Updike Aug 05 '13 at 23:34
  • @JaredUpdike: some time ago, but I think I also tried this. Thanks for chipping in – frequent Aug 06 '13 at 07:50

5 Answers5

18

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 ;-)

Community
  • 1
  • 1
joevallender
  • 4,293
  • 3
  • 27
  • 35
  • ok. trying this. I'm still waiting for the phase where the refreshes are properly... :-) – frequent Aug 06 '12 at 10:51
  • is the url.com/?something=13647 (different number each time) not working? or is the html file refreshing but your assets arent? you could add a query string to those too? (and then configuring no-cacheing for them on your server) – joevallender Aug 06 '12 at 10:56
  • no, my comment was referring to you saying "that sometimes everything refreshes properly for a while, then sometimes it doesnt". For me it never seems to work. Need a little to try out your suggestions – frequent Aug 06 '12 at 11:12
  • Absurd though it is, the random number in the URL was the only thing that worked for me with Safari on 10.12. – BSUK Nov 17 '17 at 22:28
5

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
ilo
  • 51
  • 1
  • 2
  • ah. never heard of that. Nice! Will try next time. – frequent Apr 17 '14 at 12:15
  • It's now cmd-option-r to clear the phone cache in Safari developer tools. – davemac May 05 '18 at 01:55
  • For some reason, according to the network cmd-option-r was not actually clearing the cache for me. However there is now a small button in the top right of the safari devtools network page that allows you to disable cache and that worked – ErikAGriffin Oct 06 '18 at 12:23
2

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

Jigar Pandya
  • 6,004
  • 2
  • 27
  • 45
  • good idea. Pages removed. Webserver I have to check whether I can restart. might take a while, but I will post back. Still the webserver shouldn't be the cause, because it's delivering allright to iPad and desktop. – frequent Aug 01 '12 at 07:44
  • Ya pls try and I will come to know automatically if you accept the answer ;) – Jigar Pandya Aug 01 '12 at 07:54
  • You know what was the problem... Javascript turned off. JS not loading, no consoles, looks like cache won't clear. Sure wasted some lifetime on this... Anyway. I check, because your hints were good. – frequent Aug 02 '12 at 19:49
  • sorry, I'm unchecking. This is just too much of a nuisance. I'll post a bounty. If I don't get a better answer, than you'll get the bounty, too. – frequent Aug 06 '12 at 08:57
2

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.
MidnightLightning
  • 6,715
  • 5
  • 44
  • 68
  • I'm not using the manifest yet, so I can safely rule out this being the cause. Thanks for the answer though, may come in handy later – frequent Aug 13 '12 at 10:39
  • Not using it yet? Did you ever in your testing of the site have a manifest file online? If so, under some conditions the page may be acting like it's still there. – MidnightLightning Aug 13 '12 at 11:21
  • This could be... I had an empty manifest at the very beginning, but then... since it was empty the page can't be reloaded from it. – frequent Aug 13 '12 at 11:56
  • See my edit above for untangling a simple manifest error; if you've done anything unique with the manifest file it might not be as simple as that, but it should get you in the right direction. – MidnightLightning Aug 13 '12 at 13:04
1

there is another solution with out restarting your device for safari,

  1. Go to Settings
  2. Then go down and go to Safari
  3. Then go down and see options Clear Cookie and Data as in below ImageiPhone Safari Clear Cookie and Data

  4. Now go back to your safari and you are done!

if you have any more question comment below.

Ankur Ghelani
  • 659
  • 4
  • 16