Registry / storage / 3box-shared-cache

3box-shared-cache

JSON →
library1.1.0jsnpmunverified

A lightweight cache sharing module for 3Box that uses an iframe to share cache across domains. Version 1.1.0 is the latest stable release. It is designed specifically for the 3Box ecosystem, providing proxied storage for OrbitDB and IPFS via postMessage communication. Key differentiators: enables cross-domain cache sharing without same-origin restrictions, tightly integrated with 3box-js. The library is minimal and focused on the iframe-mediated proxy pattern.

npm install 3box-shared-cache
INSTALL
IMPORT
SIG · 3BOX-SHARED-CACHE
3
3box-shared-cache
storagejavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createOrbitStorageProxy
import { createOrbitStorageProxy } from '3box-shared-cache'
const { createOrbitStorageProxy } = require('3box-shared-cache')
ESM import is recommended, CommonJS also works.
createIpfsStorageProxy
import { createIpfsStorageProxy } from '3box-shared-cache'
import createIpfsStorageProxy from '3box-shared-cache'
Named export, not default.
createServer
import { createServer } from '3box-shared-cache'
const createServer = require('3box-shared-cache').createServer
Named export, both ESM and CJS supported.

Shows how to create OrbitDB and IPFS storage proxies for cross-domain iframe communication, and how to start the server in an iframe.

import { createOrbitStorageProxy, createIpfsStorageProxy, createServer } from '3box-shared-cache'; // Proxy for OrbitDB storage const postMessage = (msg, target) => { iframe.contentWindow.postMessage(msg, '*'); }; const proxiedOrbitStorage = createOrbitStorageProxy({ postMessage }); // Proxy for IPFS storage const proxiedIpfsStorage = createIpfsStorageProxy({ postMessage }); // Server side (iframe) const server = createServer({ postMessage: window.parent.postMessage }); server.init(); server.start(); // later: server.stop();
Debug
Known issues
gotchaThe postMessage function must be bound correctly (e.g., iframe.contentWindow.postMessage) or proxy will fail silently.
fix
Ensure postMessage is a function that calls the correct target's postMessage.
affects: >=1.0.0
gotchaThe module is designed exclusively for 3Box ecosystem; using it outside 3box-js may require additional setup.
fix
Use it as part of 3box-js with iframeCache option enabled.
affects: >=1.0.0
deprecatedThe package has no active maintenance since 2020; consider alternatives if not using 3Box.
fix
Evaluate using native BroadcastChannel or other shared cache solutions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: postMessage is not a function
Passing an object or undefined as postMessage instead of a function.
fix
Ensure postMessage is a function, e.g., (msg, target) => iframe.contentWindow.postMessage(msg, target).
ReferenceError: window is not defined
Using server code in a non-browser environment (e.g., Node.js).
fix
Run server code only in a browser context (iframe).
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
postmessage-jsonrequiredUsed for serializing/deserializing messages over postMessage
Agent activity
66 hits · last 30 days
node
58
OpenAI (training)
1
Resources
3box-shared-cache — npm install 3box-shared-cache · libregistry