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

cross-domain-localstorage

v1.0.0

Published

Share localStorage across subdomains and different domains using iframe and postMessage. Works on static websites without backend.

Readme

🌍 Cross-Domain LocalStorage (No Backend, Pure JavaScript)

Access and share localStorage across:

  • ✅ Subdomains
  • ✅ Multiple domains
  • ✅ Static websites
  • ✅ Without any backend

Built using:

  • iframe
  • postMessage
  • Native browser APIs only

🚀 Live Demo Scenarios

| Demo Type | Description | |----------|------------| | 🔹 Subdomain Sharing | app.example.comadmin.example.com | | 🔹 Multi-Domain Sharing | site1.comsite2.net | | 🔹 Restricted Domains | Only selected domains allowed | | 🔹 Open Global Mode | Any domain (secured with token) |


🧠 How It Works

All domains communicate with a central storage hub:

your sites → iframe → storage hub → localStorage

  • Data is stored in ONE domain
  • All other domains access via messaging
  • Works even for static hosting

📁 Project Structure

├── demo/ │ ├── subdomain/ │ ├── multi-domain/ │ ├── restricted/ │ └── open/ ├── src/ ├── dist/ ├── storage/ │ └── storage.html ├── build.js └── README.md


⚡ Quick Start

1. Host Storage Hub

Deploy:

/storage/storage.html

Example:

https://storage.yourdomain.com/storage.html


2. Include Script

<script src="dist/cross-storage.min.js"></script>

3. Initialize

const storage = new CrossStorage({
  iframeUrl: "https://storage.yourdomain.com/storage.html",
  token: "your-secret-key"
});

4. Use Like localStorage

await storage.set("user", { name: "John" });

const user = await storage.get("user");

await storage.remove("user");

await storage.clear();

🔐 Modes Explained

1️⃣ Subdomain Mode

  • Works within same root domain
  • Uses strict origin validation

2️⃣ Multi-Domain Mode

  • Works across different domains
  • Requires shared hub

3️⃣ Restricted Mode

  • Only allowed domains can access
  • Uses whitelist

4️⃣ Open Mode (Token Protected)

  • Any domain can connect
  • Requires secret token

⚠️ Limitations

  • ❌ Cannot access storage of another domain directly
  • ❌ Requires iframe hub
  • ⚠️ Safari / Brave may restrict third-party storage

🛡️ Security Best Practices

  • Always validate event.origin
  • Never use "*" without token protection
  • Avoid storing sensitive data in plain text
  • Use encryption if needed

🧪 Demo Instructions

Each demo folder contains:

  • index.html
  • Example usage
  • Instructions

Run locally or deploy to test.

🏗️ Build

npm install
npm run build

📦 Features

  • ✅ No dependencies
  • ✅ Works on static hosting
  • ✅ Promise-based API
  • ✅ JSON support
  • ✅ Lightweight

🚀 Future Improvements

  • Encryption layer
  • BroadcastChannel sync
  • TypeScript support
  • Advanced caching

📄 License

MIT License

🙌 Contributing

PRs are welcome!

⭐ Support

If this helped you, give a ⭐ on GitHub!