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

vite-plugin-cross-origin-storage

v1.4.3

Published

Vite plugin to load chunks from Cross-Origin Storage

Readme

vite-plugin-cross-origin-storage

A Vite plugin to cache and load static assets (chunks) using the Cross-Origin Storage (COS) API.

This plugin progressively enhances your application by attempting to load vendor chunks and other assets from a shared Cross-Origin Storage, reducing bandwidth usage and improving load times across different sites that share common dependencies.

Features

  • Automatic Import Rewriting: Rewrites static imports to use COS-loaded Blob URLs when available.
  • Network Fallback: Gracefully falls back to standard network requests if COS is unavailable or the asset is missing.
  • Smart Caching: Automatically stores fetched assets into COS for future use.
  • Configurable: Easily include or exclude specific chunks using glob patterns.
  • Runtime Loader: Injects a lightweight loader to handle COS interactions transparently.

Installation

npm install vite-plugin-cross-origin-storage --save-dev

Usage

Add the plugin to your vite.config.ts (or vite.config.js):

import { defineConfig } from 'vite';
import cosPlugin from 'vite-plugin-cross-origin-storage';

export default defineConfig({
  plugins: [
    cosPlugin({
      // Configuration options
      include: ['**/vendor-*'], // Example: only manage vendor chunks
    }),
  ],
});

Configuration

| Option | Type | Default | Description | | :-------- | :-------------------------- | :---------- | :---------------------------------------------- | | include | string \| RegExp \| Array | ['**/*'] | Pattern to include chunks to be managed by COS. | | exclude | string \| RegExp \| Array | undefined | Pattern to exclude chunks from being managed. |

Recipe: Granular Vendor Splitting

To maximize caching benefits, it is recommended to split your node_modules dependencies into separate chunks. This ensures that updates to one package (e.g., react) do not invalidate the cache for others (e.g., lodash).

Add the following manualChunks configuration to your vite.config.ts:

// vite.config.ts
import { defineConfig } from 'vite';
import cosPlugin from 'vite-plugin-cross-origin-storage';

export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            // Split each package into its own chunk
            // e.g. "node_modules/react/..." -> "vendor-react"
            // e.g. "node_modules/@scope/pkg/..." -> "vendor-scope-pkg"
            const parts = id.split('node_modules/')[1].split('/');
            const packageName = parts[0].startsWith('@')
              ? `${parts[0]}/${parts[1]}`
              : parts[0];
            return `vendor-${packageName.replace('@', '').replace('/', '-')}`;
          }
        },
      },
    },
  },
  plugins: [
    cosPlugin({
      // Only manage these vendor chunks with COS
      include: ['**/vendor-*'],
    }),
  ],
});

How It Works

  1. Build Time:

    • The plugin analyzes your bundle and identifies chunks matching the include pattern.
    • It generates a stable hash for each managed chunk.
    • It rewrites imports in your code to look for a global variable (e.g., window.__COS_CHUNK_...) containing the Blob URL of the chunk, falling back to the relative network path if the variable is unset.
    • It disables the default <script type="module" src="..."> entry point in your index.html and injects a custom loader.js.
  2. Runtime:

    • The injected loader checks for navigator.crossOriginStorage.
    • If supported, it requests the file handle for each managed chunk using its hash.
    • Cache Hit: If found, it creates a Blob URL and assigns it to the corresponding global variable.
    • Cache Miss: If not found, it fetches the file from the network, stores it in COS, and then creates the Blob URL.
    • Finally, the loader imports your application's entry point, which now seamlessly uses the cached assets.

Requirements

License

Apache 2.0