12

I setup an Application Cache on a site and shortly thereafter realized its way more aggressive that I realized. I want to remove it. Permanently.

I've read that passing a changed manifest file, completely empty, with the correct MIMETYPE will remove the cache. Edit: See below. Maurice's answer is the only consistent fix.

Is this the fastest, most effective solution? Is there a better way?

And if you can specify whether or not you've actually used this functionality before with your answer I'd really appreciate it - ambiguous documentation and quirky that didn't show during testing are what got me into this situation.

Jason Goldstein
  • 1,117
  • 2
  • 11
  • 20

4 Answers4

19

The trick is to first change the manifest URL in your HTML page to something invalid so the browser will receive a 404 when loading it. Make sure to also change the original manifest otherwise the new HTML page is never downloaded. After the browser has failed to download the new manifest URL you can completely remove the manifest setting from the HTML page.

Kind of wacky but that seems to be the only reliable way of removing an existing manifest reference.

Maurice
  • 27,582
  • 5
  • 49
  • 62
  • So I actually want to set , not remove the attribute? – Jason Goldstein Jan 11 '12 at 12:50
  • 1
    Do that first, and make a change to the original manifest or the page will not be downloaded, and refresh the page. That will break the manifest link and after that you can remove the manifest attribute altogether. – Maurice Jan 11 '12 at 12:55
  • @Maurice Does the manifest URL have to be changed, or can the original manifest URL just return a 404 instead? – Svish Dec 02 '15 at 16:24
  • Just returning a 404 from the original url should be good enough. – Maurice Dec 02 '15 at 16:25
9

As of 6/25/2015 I found returning a 404 will not clear the existing appcache for Firefox, and returning a blank appcache will not clear the existing appcache for Chrome. Returning the following appcache seemed to work in IE,Chrome,Safari, and Firefox, although it is unclear by what mechanism the disabling of 'implicit' caching of index.html is accomplished.

NETWORK:
*

CACHE:
FALLBACK:
Gregory Cosmo Haun
  • 1,499
  • 17
  • 25
  • This should be accepted as as the correct answer. Thanks for sharing this! – raphael Mar 09 '17 at 11:16
  • 1
    The cache *must* start with`CACHE MANIFEST` and then a new line to be spec compliant. As for "disabling of 'implicit' caching of index.html", the only solution I know of is to include a hidden iframe, and declare the manifest in the iframe (then the page in the iframe will be cached). I haven't actually tried this, but I read of it as a solution. – Nateowami May 11 '17 at 10:04
4

If you just want it removed from your side you can do that from the Browser. I can only remember how to do it in Chrome. Go to chrome://appcache-internals/ & remove desired file(s). You can also clear cache & cookies & that should work. I've only testing that in Chrome, however.

If you want to remove it for all viewers, I know of no way to detect if they have an old cached version, but I know that keeping the attribute with a false link, like Maurice suggested, would be the only way that I would know; though, I'm sure there is another way, most likely with jQuery.

Crystal Miller
  • 741
  • 10
  • 26
2

I've been having a similar issue where I needed to reset the appcache after a failed update (i.e. force a complete removal of the appcache so that it can be re-built from scratch).

Building on Maurice's answer I present the user with a normally hidden link that opens a non-cached page, which just writes a cookie and returns the user to the previous view. This cookie tells the server to return a 404 the next time the appcache is requested, and the user is then taken through the normal login process. When the application next successfully runs it clears the cookie and caching resumes as normal.

Using a cookie in this way gets around issues where the master version of the view is stuck in the appcache, making it difficult to inject a breaking url into manifest="" i.e. the manifest url stays the same, but the server responds with a 404 until told otherwise.

notreadbyhumans
  • 607
  • 9
  • 17
  • Interesting. Although if you ultimately want to keep appcache, you can just change the manifest, which will cause the browser to refetch all the assets as if it's starting over. To get rid of the manifest permanently, Maurice was correct. – Jason Goldstein Jul 03 '13 at 13:38
  • My suggestion is really only for apps behind a login, where you can get into difficulties in triggering a successful update using the normal procedures (changing the manifest etc). – notreadbyhumans Jul 07 '13 at 15:09