Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Once an HTML document has a manifest (cache.manifest), how can you remove it?

Tags:

It seems that once you have a manifest entry, a la:

<html manifest="cache.manifest">

Then that page (the master entry in the cache) will always be cached (at least by Safari) until the user does something to remove the cache, even if you later remove the manifest attribute from the html tag and update the manifest (by changing something within it), forcing the master entry to be reloaded along with everything else.

In other words, if you have:

  • index.html (with manifest defined)
  • file1.js (referenced in manifest)
  • file2.js (referenced in manifest)
  • cache.manifest (lists the two js files)

-- removing the manifest entry from index.html and modifying the manifest (so it gets expired by the browser and all content reloaded) will not stop this page from behaving as if it's still fully cached. If you view source on index.html you won't see the manifest listed anymore, but the browser will still request only the cache.manifest file, and unless that file's content is changed, no other changes to any files will be shown to the user.

It seems like a pretty glaring bug, and it's present on iOS as well as Mac versions of Safari. Has anyone found a way of resetting the page and getting rid of the cache without requiring user intervention?

like image 854
Michael F Avatar asked Dec 27 '10 22:12

Michael F


People also ask

What is a manifest file in html?

The manifest file is a simple text file that lists the resources the browser should cache for offline access. To learn more about how to create the manifest file, please read our HTML5 Application Cache chapter.

What does cache do in manifest file?

The CACHE section contains files you want to load and store on the user's machine. The first time the user loads your app, the browser will store all the files in the CACHE section of your app cache manifest. The NETWORK section contains all the resources that require a network connection to be loaded.

Should manifest JSON be cached?

Yes you should cache your manifest. json file, because if you a building a PWA, then it must have a functionality to Add to home screen . In your manifest file, it contains a start_url that needs to be cached by service worker and should return a 200 response when offline.

What is the MIME type for HTML5 application cache manifest file?

A manifest file must be served with the mime-type text/cache-manifest .


2 Answers

Ive been researching the same question, and it doesnt appear to be an api to:

  1. dynamically trigger that a page is cached
  2. dynamically cause a page to stop being cached.

Here are the best resources I have found:

http://www.html5rocks.com/tutorials/appcache/beginner/

http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone

In particular, this quote from the first link:

If the manifest file or a resource specified in it fails to download, the entire update fails. The browser will continue to use the old application cache in the event of such a failure.

Otherwise, there is no mention anywhere about unloading the cache.

Seems to suggest that you cant force an error to get it to uncache. However, as noted below, the spec suggests that if an error occurs while downloading the manifest file, the entire cache will be removed.

In google chrome, the user can go to the following URL:

chrome://appcache-internals/

And manually disable the cache. Of course, the next time they visit the page, it will be recached if the page has the manifest property set.

If you look at the specification:5.6 Offline Web applications

It seems to suggest a situation where the cache is removed. Specifically, section 5.6.4.5:

If fetching the manifest fails due to a 404 or 410 response or equivalent, then run these substeps: Mark cache group as obsolete. This cache group no longer exists for any purpose other than the processing of Document objects already associated with an application cache in the cache group. If cache group has an application cache whose completeness flag is incomplete, then discard that application cache.

It then says:

If this was a cache attempt, discard cache group altogether.

Basically, if the request for the cache manifest file results in a 404, then the entire cache should be discarded. So, have you tried to have the server return a 404 or 410 when the cache manifest file is requested? That should work. The trick is to only return the 404 / 410 for the pages you want to remove the manifest from (perhaps using url parameters?).

like image 150
mikechambers Avatar answered Oct 20 '22 03:10

mikechambers


One possible solution:

  • modify the manifest (so it reloads)
  • modify the master file (index.html) to reference a non-existant manifest, so it gets a 404

Hardly elegant, but it seems to work. The main problem then is that you're stuck with this 404-generating false manifest entry until everyone who has ever been to your site has returned and had their cache cleared.

There has got to be a better way...

like image 29
Michael F Avatar answered Oct 20 '22 05:10

Michael F