How to disable cache on IOS safari?

2019-03-08 19:42发布

问题:

Is there a way to disable caching on ipad/iphone? I want to run some automated tests for non-cache experience.

回答1:

I just stumbled across a way to disable cache in Safari on iOS:

iOS

  1. Open Settings
  2. Navigate to Safari > Advanced
  3. Enable Web Inspector
  4. Switch back to Safari and load a web page

Desktop

  1. Open Safari
  2. Navigate to Safari > Preferences > Advanced tab
  3. Enable the Develop menu
  4. In the Develop menu, select Your iOS Device Name > The Page You Want to Debug
  5. Press Command-Shift-R to reload while disabling cache
  6. Bonus: This is a full Web Inspector on your computer inspecting a page on your iOS device

If you want something more permanent, you'll either have to go the proxy route or make a UIWebView/WKWebView wrapper app that disables caching.



回答2:

There is a way to effectively disable caching on iphone/ipad/IOS.

Install Fiddler on a windows desktop, and allow remote computers to connect:

In IOS, setup a proxy under your wifi connection settings, pointing to to the IP address of the computer you are running fiddler on, and on port 8888 (assuming you haven't changed it from default in fiddler):

By now, fiddler should be intercepting all web requests your device is making.

You can now disable caching from the Rules -> Performance menu in fiddler.



回答3:

I could be wrong, but on iOS does putting Safari in Private Browsing mode disable cache?



回答4:

Doesn't seems like possible. On desktop safari, there is a option to disable cache in developer tools, however there isn't one on mobile safari. I didn't find the option in other browsers like opera neither.

If you wanna try, you can overwrite a desktop firefox's user agent string and make it a fake ipad mobile browser, and then disable cache. But that will depends on what you want to test and it could not work at all.

Hope this helps.



回答5:

Using iOS Simulator 9.0 I have been finding that both the Developer - Disable Caches menu item and Cmd-Shift-R reload have both failed to completely bypass the cache for whatever reason. The only thing that worked was to hold shift and press this reload button in the Safari Developer tools: