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

@qwikdev/pwa

v0.0.4

Published

Qwik PWA

Downloads

114

Readme

Qwik PWA 📱

Turn your Qwik Application into an offline compatible PWA (Progressive Web Application) using Workbox but without the hassle.

Installation

npm install --save-dev @qwikdev/pwa

vite.config.ts:

import { qwikPwa } from "@qwikdev/pwa";

export default defineConfig(() => {
  return {
    define: {
      // (optional) enables debugging in workbox
      "process.env.NODE_ENV": JSON.stringify("development"),
    },
    plugins: [
      qwikCity(),
      qwikVite(),
      // The options are set by default
      qwikPwa({
        /* options */
      }),
    ],
  };
});

src/routes/service-worker.ts:

import { setupServiceWorker } from "@builder.io/qwik-city/service-worker";
import { setupPwa } from "@qwikdev/pwa/sw";

setupServiceWorker();

+setupPwa();

- addEventListener("install", () => self.skipWaiting());

- addEventListener("activate", () => self.clients.claim());

- declare const self: ServiceWorkerGlobalScope;

By default, your application will be auto-updated when there's a new version of the service worker available and it is installed: in a future version, you will be able to customize this behavior to use prompt for update:

import { setupServiceWorker } from "@builder.io/qwik-city/service-worker";
import { setupPwa } from "@qwikdev/pwa/sw";

setupServiceWorker();
setupPwa("prompt");

public/manifest.json:

"background_color": "#fff",
+ "theme_color": "#fff",

For more information, check the following pages:

src/components/router-head/router-head.tsx:

// PWA compatible generated icons for different browsers
import * as pwaHead from "@qwikdev/pwa/head";

export const RouterHead = component$(() => {
    ...
      {pwaHead.meta.map((l) => (
        <meta key={l.key} {...l} />
      ))}
      {pwaHead.links.map((l) => (
        <link key={l.key} {...l} />
      ))}
    ...

Make sure you remove the <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> line in your router-head file.

Now your application is PWA-friendly.

Precache

One feature of service workers is the ability to save a set of files to the cache when the service worker is installing. This is often referred to as "precaching", since you are caching content ahead of the service worker being used. Chrome for Developers

Assets

Assets like js modules generated by qwik (q-*.js), images, public/ assets, or any file that's emitted in the dist/ directory by the build step would be precached when the service worker instantiates, so the plugin makes sure it provides the best client-side offline experience.

Routes

By default in this plugin, every route that does not include params (/ or /demo/flower) is precached on the first run of the application when the browser registers the service worker.

For the rest of the defined routes (routes with params like /dynamic/[id], SSG routes, or API routes), they are not precached, but there are workbox navigation routes defined that would cache them on-demand and per request, the reason is precaching too many assets on the first run would cause a laggy experience for the user, especially when these kind of routes have the potential to generate so many more files.

Imagine there's an SSG /blog/[id] route that generates 120 blog posts, in this case, fetching 120 pages of blog posts in the application startup would not seem ideal.

Solution

Just fetch the desired page or asset so it gets cached for later uses.

fetch("/blog/how-to-use-qwik");

API Routes

For API routes and any other routes that do not meet the conditions mentioned above, there's a Network-First handler.

Manifest

The plugin would generate all of the adaptive icons needed for different devices with different ratios in manifest.json based on your main icon in the build process using @vite-pwa/assets-generator.

Screenshots

For full PWA compatibility, you can put your screenshots with the following pattern in the public/manifest.json file.

    ...
    "screenshots": [
        {
            "src": "/screenshot.png",
            "type": "image/png",
            "sizes": "862x568"
        },
        {
            "src": "/screenshot.png",
            "type": "image/png",
            "sizes": "862x568",
            "form_factor": "wide"
        }
    ]

For beautiful screenshots, you can use Progressier Screenshots Generator.