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 🙏

© 2026 – Pkg Stats / Ryan Hefner

shared-worker-fallback

v0.1.0

Published

Run SharedWorker-style code with a dedicated worker fallback.

Readme

shared-worker-fallback

shared-worker-fallback lets browser applications use the Shared Worker programming model when only dedicated workers are available.

Use shared-worker-fallback/client to install the fallback globally, or import SharedWorker from shared-worker-fallback/client/ponyfill to leave the global unchanged. Import shared-worker-fallback/worker before the worker implementation. These examples assume a bundler that resolves npm package subpaths.

When SharedWorker is unavailable, either client entrypoint creates a dedicated Worker and transfers a MessagePort to it. The worker adapter then dispatches a Shared Worker-style connect event. Native Shared Worker implementations are used when available. Environments loading a client entrypoint are expected to support dedicated workers.

Installation

npm install shared-worker-fallback

The client and worker subpaths are side-effect-only modules and export no values. The client/ponyfill subpath exports SharedWorker without modifying globalThis.

Compatibility model

The fallback provides API compatibility so application and worker code can be written around SharedWorker, SharedWorkerGlobalScope, onconnect, and MessagePort in both environments.

It does not reproduce Shared Worker identity or sharing semantics. Each fallback SharedWorker instance owns a separate dedicated worker, so global state is not shared between instances, tabs, windows, or other browsing contexts. Code using this fallback should communicate through the provided port and must not depend on multiple constructors connecting to the same worker process.

The fallback forwards the shared worker's URL, name, type, and credentials to the dedicated worker. Shared-worker-only lifetime behavior such as extendedLifetime cannot be emulated.

Application: global fallback

Load the client adapter before any application code reads or constructs SharedWorker. The worker is a module because its entrypoint uses a static import:

import "shared-worker-fallback/client";

const worker = new SharedWorker(new URL("./worker.js", import.meta.url), {
	name: "application-worker",
	type: "module",
});

worker.port.addEventListener("message", ({ data }) => {
	console.log(data);
});

worker.port.start();

Application: ponyfill

Import the constructor directly when the application should not modify globalThis.SharedWorker:

import { SharedWorker } from "shared-worker-fallback/client/ponyfill";

const worker = new SharedWorker(new URL("./worker.js", import.meta.url), {
	name: "application-worker",
	type: "module",
});

Worker

Load the worker adapter first in the worker entrypoint:

import "shared-worker-fallback/worker";

self.addEventListener("connect", ({ ports: [port] }) => {
	port.addEventListener("message", ({ data }) => {
		port.postMessage(data);
	});
	port.start();
});

The same worker implementation can run in a native SharedWorkerGlobalScope or in the adapted dedicated-worker scope.

For a classic worker, bundle the worker adapter and implementation into one classic script instead of using the static import shown above.