JS Client for interacting with the Myel CDN.
Retrieve content addressed data from a decentralized network of cache providers. This client is still highly experimental and API may still change at any moment.
As an NPM package
npm install @dcdn/client
As a service worker
- Install
@dcdn/service-worker
in your project and server@dcdn/service-worker/dist/index.min.js
from your origin. - Register the service worker:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then((reg) => {
// registration worked
console.log('Registration succeeded');
}).catch((error) => {
// registration failed
console.log('Registration failed with ' + error);
});
}
As a Cloudflare worker
- Make sure you have wrangler installed and a Cloudflare workers account
npm install -g @cloudflare/wrangler
- Login and set your account ID in
wrangler.toml
wrangler login
- Deploy to a
*.workers.dev
subdomain
cd dists
wrangler publish
When using from a worker you can directly request the content using IPFS paths:
/bafyreiaemos3x3k5fmycs64ry3otobineo4wdz73ccrqxrlzt7gmtzhbmm/red-frog.jpg
if running in a service workerhttps://yourdomain.workers.dev/bafyreiaemos3x3k5fmycs64ry3otobineo4wdz73ccrqxrlzt7gmtzhbmm/red-frog.jpg
if using a Cloudflare worker
When using the client directly in your application (We recommend using in a worker so as not to block the main thread).
import {create} from '@dcdn/client'
(async () => {
const client = await create()
const myImage = document.querySelector('img');
const resp = await client.fetch('bafyreiaemos3x3k5fmycs64ry3otobineo4wdz73ccrqxrlzt7gmtzhbmm/red-frog.jpg')
myImage.src = URL.createObjectURL(await resp.blob());
})();