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

@solutas/zephyr

v0.0.4

Published

Lightweight service worker library designed to provide efficient caching strategies for web applications

Downloads

8

Readme

Zephyr

Zephyr is a lightweight service worker library designed to provide efficient caching strategies for web applications. It offers a simple yet powerful way to cache network requests and responses using IndexedDB, enabling offline access and performance optimization.

⚠️ Please note that Zephyr is currently under development and may not be suitable for production use. Use at your own risk.

Installation

You can either install Zephyr via npm:

npm install @solutas/zephyr --save

or load the installer via CDN

Setup

To integrate Zephyr into your web application, follow these steps:

  1. Create the zephyrConfig.js file to your root directory of the project.
  2. Add the following code to your HTML file, preferably before the closing tag or use include the zephyrInstall.js script from lib, to register the service worker:
<!-- in your head section -->
<script type="module" src="https://www.unpkg.com/@solutas/[email protected]/lib/zephrInstall.js"></script>

or you can manually load the web worker like this (or copy the file when isntalled via npm):

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('./zephyrConfig.js', {scope: "/"})
      .then(registration => {
        console.log('Zephyr worker registered:', registration);
      })
      .catch(error => {
        console.error('Zephyr worker registration failed:', error);
      });
  });
}

Configuration

In the zephyrConfig.js file, define your caching rules and configuration. Zephyr uses regular expressions (regex) for pattern matching in the rules. Here are some examples:

  • .*\\/api\\/getProducts$: Matches any URL ending with /api/getProducts.
  • .*\\.(png|jpg|js)$: Matches any URL ending with .png, .jpg, or .js.
  • ^https?://example.com/api/.*\\.json$: Matches any JSON file under the /api path on example.com.
  • .*\\.json$: Matches any JSON file.

// either use cdn or copy the worker to your public site somewhere, while the zephyrConfig.js file must be in root
// this can be anywhere
importScripts("https://www.unpkg.com/@solutas/[email protected]/lib/zephyrWorker.js");

// Define your configuration, including resources to cache
const config = { 
    rules: [
        {
            test: '.*\\/api\\/graphqlapi',
            method: 'POST',
            cache: '1440', // 1 day in minutes
        },
        {
            test: '.*\\.(png|jpg|js)$',
            method: 'GET',
            key: '$path',
            cache: 90, // 1 hour 30 minutes in minutes
        },        
    ]
};

// Initialize the worker with the configuration
if (initZephyr) {
    initZephyr(config);
} else {
    console.error("Zephyr worker initialization function not found.");
}

Replace the example rules with your specific caching requirements.

Debug

You can add ?zephyrDebug=true to the url to get some more debug information in the developer console.

What It Does

Zephyr intercepts network requests made by your web application and caches responses based on the defined rules in zephyrConfig.js. This allows for faster subsequent loads of resources and enables offline access to cached content. Zephyr can also cache POST requests. It will take the hash of the payload as key to differenciate. Please be careful not to save sensitive data.

GitHub Issues

For inquiries, bug reports, and support, please use GitHub Issues: Zephyr Issues

License

Zephyr is licensed under the Apache License 2.0. See the LICENSE file for details.

© 2019-2024 SOLUTAS GmbH. All Rights Reserved.