Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending cache manifest to existing site

Is it possible to add a cache manifest programmatically right after the page was loaded? Like adding the attribute to the html tag with JavaScript and re-init/re-load the page?

I want to add a cache manifest to a page but cannot edit its HTML itself.

like image 368
K. D. Avatar asked Apr 25 '15 10:04

K. D.


People also ask

How to cache a manifest file in HTML?

The attribute manifest="<path>" must be added to the html element in order for the cache manifest file to work. Example: The argument to the manifest attribute is a relative or absolute path to the manifest file. Consider the HTML file given below.

Is it possible to change manifest-based caching?

Note: manifest-based caching mechanism has been deprecated. Use service workers instead. The manifest attribute has only effect during early stages of page load, thus changing it via regular DOM interfaces has no effect, Window.applicationCache interface instead. Compatibility unknown; please update this.

What is application cache in HTML?

Using the application cache - HTML | MDN HTML5 provides an application caching mechanism that lets web-based applications run offline. Developers can use the Application Cache (AppCache) interface to specify resources that the browser should cache and make available to offline users.

What is the fallback section in a cache manifest file?

The fallback section in a cache manifest file can be used to substitute online resources that cannot be cached or were not cached successfully. CACHE MANIFEST FALLBACK: / /offline.html NETWORK: …


2 Answers

Some tests I did a while ago found that it was only working if you redirect to a site where the cache manifest is correctly specified.

The application cache works per domain. This gives us two different cases: 1. it's a site on our domain or 2. it' an external site.

  1. Because you only need to specify the manifest on the main site (or any other site that is guaranteed to be visited, otherwise you can get strange behaviour) you can just put a bouncer in front of your house: Make a dummy page (=bouncer, displaying a spinner or progress bar) whith the cache manifest correctly specified. This dummy page can also check if there were changes and swap the cache. After loading all resources you just redirect to the "real" entry point of your application (the bouncer granted access).

  2. If it is an external page, then you have to choose another workaround like reading the content of the site on the server side and correct it there (so that it looks like it's a site on your domain). You can also cache the external site like any other resource and load the external site in an iframe, but simply put: the URI displayed in the browser has to be on your domain. If you think about it, it's just reasonable, otherwise I could make a site that caches stackoverflow forever and everyone who visited my site will have no more updates from stackoverflow (oversimplified, but it should get the point accross).

like image 61
maraca Avatar answered Oct 18 '22 01:10

maraca


The cache-manifest describes the files needed to run your "application" "offline". You can not set the manifest attribute after the page was loaded. The HTML file is already sent and the browser will not react to a dynamically added manifest attribute.

You could try "scraping the page" on server side and wrap/embed the content into a new HTML page with manifest (proxy-style).

like image 31
Jens A. Koch Avatar answered Oct 18 '22 00:10

Jens A. Koch