Access and share localStorage across:
- β Subdomains
- β Multiple domains
- β Static websites
- β Without any backend
Built using:
iframepostMessage- Native browser APIs only
| Demo Type | Description |
|---|---|
| πΉ Subdomain Sharing | app.example.com β admin.example.com |
| πΉ Multi-Domain Sharing | site1.com β site2.net |
| πΉ Restricted Domains | Only selected domains allowed |
| πΉ Open Global Mode | Any domain (secured with token) |
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
βββ demo/ β βββ subdomain/ β βββ multi-domain/ β βββ restricted/ β βββ open/ βββ src/ βββ dist/ βββ storage/ β βββ storage.html βββ build.js βββ README.md
Deploy:
/storage/storage.html
Example:
https://storage.yourdomain.com/storage.html
<script src="dist/cross-storage.min.js"></script>const storage = new CrossStorage({
iframeUrl: "https://storage.yourdomain.com/storage.html",
token: "your-secret-key"
});await storage.set("user", { name: "John" });
const user = await storage.get("user");
await storage.remove("user");
await storage.clear();- Works within same root domain
- Uses strict origin validation
- Works across different domains
- Requires shared hub
- Only allowed domains can access
- Uses whitelist
- Any domain can connect
- Requires secret token
- β Cannot access storage of another domain directly
- β Requires iframe hub
β οΈ Safari / Brave may restrict third-party storage
- Always validate
event.origin - Never use
"*"without token protection - Avoid storing sensitive data in plain text
- Use encryption if needed
Each demo folder contains:
index.html- Example usage
- Instructions
Run locally or deploy to test.
npm install
npm run build- β No dependencies
- β Works on static hosting
- β Promise-based API
- β JSON support
- β Lightweight
- Encryption layer
- BroadcastChannel sync
- TypeScript support
- Advanced caching
PRs are welcome!
If this helped you, give a β on GitHub!