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

mwc-pwa-reload

v1.0.5

Published

A reload snack-bar for PWA which gives the user the option to reload the page to see the new version of the web app. Build with Material Components for the Web.

Downloads

11

Readme

<mwc-pwa-reload>

A snack-bar for PWAs that gives the user the option to reload the page on a new version of the web app. If the snackbar is dismissed, the Service Worker will remain in the waiting phase and the new version of the website will not be loaded.

npm version Dependency status


👷‍ Build with

🧱 Material Components for the Web (on top of Material Snackbar).

🧱 Workbox

🚀 Getting started

Install

  • npm

  1. Inside your project directory run

    npm install mwc-pwa-reload
  2. Import component

    • Inside your app's JavaScript file (ex: app.js)

      import 'mwc-pwa-reload';

    OR

    • Add a <script> tag in an HTML file (ex: index.html)

      <script src="./node_modules/mwc-pwa-reload/dist/index.js"></script>
  • web

    <script type="module" src="https://unpkg.com/mwc-pwa-reload"></script>

Configure Service Worker

  1. Add this listener to your Service Worker file (ex: sw.js)

     addEventListener('message', event => {
       if (event.data && event.data.type === 'NEW_VERSION') {
           skipWaiting();
       }
     });

Include component in HTML

  1. Include the <mwc-pwa-reload> element inside your HTML file (ex: index.html)

     <mwc-pwa-reload></mwc-pwa-reload>

⚠️ The first time you push your code live the snackbar will not be shown, however it will be shown on every new version after that.

⚠️ In the above example the component will run on default options that are explained below 👇👇

📚 API Docs

💡 For the full list look at the Material Snackbar Docs

JavaScript

  • swUrl: String - Local Service Worker JavaScript file url

    • Default = './sw.js'

  • swScope: String - The scope by which Service Worker has been registered

    • Default = '/'

  • labelText: String - Snackbar main text

    • Default = 'A new version is available 💎'

  • reloadTextColor: String - Reload action button color

    • Default = '#18ffff'
    • Change color also with the CSS variable --mdc-snackbar-action-color

    More here 👉 Material Color Palette

  • timeout: String|Number - Snackbar's timeout until it is dismissed (ms)

    • Default = 6000
    • ⚠️ Need to be between 4000 and 10000
  • onDismiss: Function - Callback when snackbar has been dismissed after timeout or by clicking on the X button.

    • Default = null

JavaScript API Example

const mSnackbar = document.querySelector('mwc-pwa-reload');

mSnackbar.swUrl = './service-worker.js';
mSnackbar.swScope = '/';
mSnackbar.labelText = 'Hello there! New version in town!';
mSnackbar.timeout = 8000;
mSnackbar.reloadTextColor = '#d500f9';

HTML

You can either configure the component using JavaScript or even by HTML attributes.

HTML API Example

<mwc-pwa-reload 
  sw-url="./service-worker.js" 
  sw-scope="/"
  timeout="8000"
  reload-text-color="#d500f9"
></mwc-pwa-reload>

Logging

Logging is enabled only when the component has a dev attibute like so:

<mwc-pwa-reload dev></mwc-pwa-reload>