npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browser-cachier

v1.1.2

Published

Simple, manually controlled Cache Storage library

Downloads

3

Readme

Cachier

Warning: Cachier is currently in beta. Only usable in the browsers that has Service Worker and Cache Storage.

Cache your content on clients browser with Cachier! Cachier, uses Cache Storage for caching static pages & files. The Service Worker technology serves it over cache for your clients. It also allows clients view offline pages.

Features

  • The caching process controlled by owner
  • Lightning fast page load
  • Offline page views
  • Less network requests

Table of Contents

Install

You can install the library via npm.

npm install browser-cachier --save

or via yarn:

yarn add browser-cachier

Warning: You need to put cachier-service-worker.js to your sites root directory.

Cachier

API

Warning: add, remove, update and delete updates the current state of cachier. All events below are returning instance with a promise.

new Cachier(config: Object): Cachier

Cachier instance takes one argument which is config. The accepted configs described below.

cachier.add(urls: Array, callback: Function~response): Cachier

Adds provided url list to cache storage. If the provided url is in the cache already, it doesn't add it again. The url list returned from callback.

cachier.get(url: String <Optional>, callback: Function~response): Cachier

Get cache key from storage. If url argument not sent by user, it gets all otherwise gets single one. As a result it returns true or false according to its existence

cachier.update(urls: Array, callback: Function~response): Cachier

Updates the cache content of provided files. The url list returned from callback.

cachier.delete(urls: Array, callback: Function~response): Cachier

Delete provided url list from cache storage. The url list returned from callback.

cachier.clear(callback: Function~response): Cachier

Empty all cache storage. The deleted item list returned from callback.

Options

version {String|Number}

Sets a version to cache storage. After caching process completed for the first time, it will stay till user clears the cache storage. To overcome this, you can upgrade the version to a greater value. It will clear out of date storages and will set a new one.

serviceWorkerPath {String}

Cachier is using cachier-service-worker.js to create a layer between network requests and cache. File should be placed on your root directory to observe all scope. This parameter is the location of service worker.

debug {Boolean}

If it is true, it gives information on the console about what is going on.

Listeners

stateChange

Everytime change happens on cache storage over API events, stateChange event triggers. It is bound to document. With a simple eventListener you can catch-up state changes.

Example

import Cachier from 'browser-cachier';

let urlsToCache = ['/dummy/style.css', '/dummy/dummy.json'];
let cachier = new Cachier({ version: 1 });

cachier.add(urlsToCache, (response) => {
  console.log(response);
});

cachier.get(response => {
  console.log('Get: ', response);
});

cachier.get('/dummy/style.css', response => {
  console.log('Get: ', response);
});

// Remove specific cache items after 1500ms
setTimeout(() => {
  cachier.delete(urlsToCache, response => {
    console.log('Delete: ', response);
  });
}, 1500)

// Remove whole cache on page load
window.onload = function () {
  cachier.clear();
};

// Capture state change events
document.addEventListener('stateChange', function (result) {
    console.log('State: ', result.detail)
});

Contributing

Do not hesitate to contribute! It is a new born baby and open to ideas.

For more information, please checkout the contribution document.

Copyright

Copyright (c) 2017 tugayilik. See LICENSE.md for further details.