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

js-static-cache

v1.0.3

Published

Provide functionality for caching all application resources and GET requests

Downloads

3

Readme

Motivation

As we can see, web surfing became more mobile and there is no guarantee that your user will always on 4g/5g connection, so here we should deliver to our users some offline functionality. This library will help you easily add offline cache of all GET request for your app. Without complicated setup, a lot of settings and any other things, simple resource caching.

Installation

npm i js-static-cache

Usage

All is you need it's array of resources or URL's to be cached, you can find plugin or library that will handle this job for you by your build lib (parcel, webpack, etc).

Next create (if you don't do it already) service worker file and instantiate StaticCacheController at start of script.

Don't forget add fetch event listener to globalObject with controller handler

import { StaticCacheController } from "@essaenko/js-static-cache";

const controller: StaticCacheController = new StaticCacheController({
  version: 1, // Required field: version will helps you remove old cache and recreate storage with new one
  name: 'myAppCache', // Optional field: you can name cache for your app to exactly know where your data stored, default name is 'static_cache_controller'
  manifest: ['/', '/index.js', '/index.css', '/api/json/news'], // Required field: array of assets or url's to be cached
  shouldProcessRequests: true, // Optional field: if you want to cache all sent GET requests - set this field to true, false by default
  debug: true // Optional field: This option can get you some information for debugging
});

self.addEventListener('fetch', controller.onFetch);

StaticCacheController - realises singleton pattern, if you'll try to create more than one instance it will return you existed one

Examples

You can find some examples in folder 'examples' Just run npm run serve:examples and navigate to http://localhost/

Commands

npm run watch - ts build watcher

npm run build - builds project by ts-compiler

npm page

https://www.npmjs.com/package/js-static-cache