resource-cacher

0.1.1 • Public • Published

resource-cacher

resource loading and cache in Browser.

Load and cache it,

import { ONE_MINUTE } from 'resource-cacher';
import { loadResource } from 'resource-cacher';
 
const url = './img.png';
const expiresIn = ONE_MINUTE;
 
loadResource( './img.png', expiresIn ).then( ( blobUrl ) => {
 
    const img = new Image();
    img.src = blobUrl;
    document.body.appendChild( img );
 
} );

Once it was cached, it will be loaded from memory without http request.

const url = './img.png';
const expiresIn = ONE_MINUTE;
 
loadResource( './img.png', expiresIn ).then( ( blobUrl ) => {
 
    const img = new Image();
    img.src = blobUrl;
    document.body.appendChild( img );
 
} );

To force clear cache, use clearCacher().

import { clearCacher } from 'resource-cacher';
 
const url = './img.png';
 
clearCacher( url );

Readme

Keywords

Package Sidebar

Install

npm i resource-cacher

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

10.8 kB

Total Files

11

Last publish

Collaborators

  • yomotsu