2

Well all right, maybe it doesn't kill web development completely... but it's certainly irritating. =)

I have been testing a site recently using various desktop and mobile browsers. So far, the only one that has given me significant trouble is Safari running on the iPhone 5, which uses a level of caching beyond anything I have seen before that seems nearly impossible to get rid of, which I now call Super Caching. This Super Caching has prevented me from testing my site as I am unable to test any changes - not to the css style, back-end c#, front-end javascript, aspx design, nada. I have tried the following methods to attempt to clear the cache for this page (both separately and all together):

  1. Close all tabs in Safari, then close Safari entirely (double tap home button, close Safari icon there)

  2. Settings -> Safari -> Clear History + Settings -> Safari => Clear Cookies and Data. Checking the Website Data after doing this confirms there is nothing there and shows 0 bytes of stored data.

  3. Shut down my phone completely (not just sleep)

  4. Change the url to my site by appending garbage information like ?random=pleasedontcacheme&random2=123

  5. Add code to my site to try and prevent caching... which of course doesn't work because these changes are never retrieved by the phone's browser.

In short, testing has become a small nightmare at the moment. While any tips for how to actually destroy Safari's obnoxious caching would be greatly appreciated, I am more interested in making sure that this does not happen during development in the future. So my question is, for the current Safari browser, what is the best way to stop it from caching a website?

So far I have added the following to the Page_Load of my site's default page:

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
            HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
              HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Cache.SetNoStore();

        Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
        Response.AppendHeader("Pragma", "no-cache");
        Response.AppendHeader("Expires", "0");

I have also seen others use meta tags, though they have been described as a bit hacky. (As found here).

I am still working towards a way to retake control of my iPhone's cache, but in the meantime, I would like to ask those who might be more experienced with this particular issue how well the above methods work for getting around the caching issue (during development mostly, but also good to know for future reference). Or, are there other solutions that have been found helpful for this browser/system combo?

Thank you very much in advance for any tips or advice. =)

Community
  • 1
  • 1
user2912928
  • 170
  • 3
  • 15
  • Were you able ever to figure this out? I am dealing with super-caching too. No matter what I do, iOS Simulator will not let go of the files grinding testing to a halt. Did you ever find any good information? – Dustin M. Mar 05 '14 at 19:35
  • Also interested in any hints? Safari won't even call my server via ajax as it's cached an invalid response (potentially a CORS header). If I change the protocol (from http to https) it works but otherwise... – toxaq Oct 07 '14 at 13:04
  • Actually found out what my problem was, the page was being redirected to SSL due to Strict-Transport-Security being on in the base domain. Of course this only works if you've visited the base/root domain for Safari to remember this rule. Explains why I was getting two completely different results for two identical devices... – toxaq Oct 07 '14 at 14:10

0 Answers0