1.0.0 • Published 4 years ago
dynamic-cache v1.0.0
Install
$ npm i dynamic-cacheAPI
Table of Contents
constructor
Creates a DynamicCache.
const headers = new Headers({ 'Content-Type': 'text/plain' })
const cache = new DynamicCache('text', headers)Parameters
namespacestring Namespace of the files in this cacheheadersHeaders Headers to use for this cache files
put
Puts a file in the cache.
const url = await cache.put('foo', 'bar')
await fetch(url).then(res => res.text()) // => "bar"Parameters
filenamestring The filename of the resourcecontentstring The content of the resourceheadersHeaders to be used (optional, defaultthis.headers)
Returns any The full path of the resource, including the cache's prefix
register
Registers the service worker.
// note you must serve `sw.js` at a higher level than your current url location
await DynamicCache.register('/sw.js')Parameters
urlstring The url of the service worker file (can find it underdist/cjs/sw.jsordist/esm/sw.js)optionsRegistrationOptions Service worker registration options (@see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration) (optional, default{scope:'/'})
Contribute
All contributions are welcome!
License
MIT © 2021 stagas
1.0.0
4 years ago