dynamic-cache
v1.0.0
Published
service worker where cache can be updated dynamically at runtime
Downloads
36
Maintainers
Readme
Install
$ npm i dynamic-cache
API
Table of Contents
constructor
Creates a DynamicCache.
const headers = new Headers({ 'Content-Type': 'text/plain' })
const cache = new DynamicCache('text', headers)
Parameters
namespace
string Namespace of the files in this cacheheaders
Headers 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
filename
string The filename of the resourcecontent
string The content of the resourceheaders
Headers 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
url
string The url of the service worker file (can find it underdist/cjs/sw.js
ordist/esm/sw.js
)options
RegistrationOptions 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