Skip to content

isocroft/Cachr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cachr

This is a very small library that serves to provide a fallback to Service Workers in browser where support is absent. Application Cache has relatively good browser support and is well suited for a service worker fallback. For iOS support see this docs link on offline storage on the iPhone

It simply implements Application Cache with an easy interface.

Support

  • Internet Explorer 10+
  • Safari 4+
  • Firefox 3.5+
  • Opera 11.6+
  • Chrome 4+

Setting up (How to)

  • Create an .appcache file with the name manifest in the root folder of your web project.
  • Copy in the offline.html file into the root folder of your web project.
  • Create your application index file and link it to Cachr using a script tag.
  • Use the script shown below to activate Cachr
  • Beware of these pitfalls as you use applicationCache and Cachr
	<script type="text/javascript">
		!function(win){
			'use strict';

			if(win.applicationCache && win.Cachr){
				win.Cachr.go();
			}
		}(this);
	</script>

And that's all to it.

Important Info

The manifest.appcache file must be in the root of your application as well as the offline.html file. By extension, this means that both files must be in the same domain so as to avoid Same-Origin Policy restrictions by the browser. Also, you have to configure the server to serve the manifest.appcache file with the correct mime type and force the browser never to cache it (preferrably using a .htaccess file). Please see the examples folder for more insight

Caveats/Gotchas

If any of the files listed in the manifest.appcache file is modified, the manifest.appcache file itself must also be modified. You can do this by altering the date comment on the second line using a server script or a schedule script perhaps so you don't have to do it manually yourself everytime.

Licence

MIT license

Issues/Bugs