nimda95 / cache-js

A simple library for caching js and css in localStorage's HTML5 API

Home Page:https://aymanedev.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache-js.js

The localStorage cache for javascript and stylesheet libraries

Using the library is pretty simple

1. The Array object containing the sources

var resources = {
    onFinished: function() {
        // Callback to call when all files are loaded into the html page
	// [Suggestion] : Make this your window.onload()
    },
    files: {
        "unique name of the resource": {
            uri: "url to the file as it would be in the html page",
            version: "-",
            attributes: [{
                name: "name of the attribute",
                value: "value of the attribue"
            }],
            type: "style pr script"
        }
    }
};

Note: if the version is set to - the file will be always downloaded and never use the cached version

2. implementing the library

cacheJs.initialize(resources);

3. Recommendations

It is recommended to insert the above code directly into the html code as a script tag with the call for the library before it, instead of making another javascript file containing the above code.

About

A simple library for caching js and css in localStorage's HTML5 API

https://aymanedev.com

License:GNU General Public License v3.0


Languages

Language:JavaScript 80.2%Language:HTML 19.8%