ipfs-provider icon indicating copy to clipboard operation
ipfs-provider copied to clipboard

Batteries-included: load js-ipfs from CDN when no instance is provided

Open lidel opened this issue 6 years ago • 2 comments

below is just a quick idea, let me know your thoughts on this

Context

Right now one needs to explicitly pass ipfs instance for js-ipfs to work:

const { ipfs, provider } = await getIpfs({
  tryJsIpfs: true,
  getJsIpfs: () => import('ipfs'),
  jsIpfsOpts: { /* advanced config */ }
})

This is great, but some folks just want "batteries-included" experience where ipfs-provider takes care of loading and initializing existing browserified js-ipfs (think pocs, demos, prototyping, quickly switching between different versions/bundles etc).

Load js-ipfs from custom URL

A solution is to allow user to pass jsIpfsBundleUrl

const { ipfs, provider } = await getIpfs({
  tryJsIpfs: true,
  jsIpfsBundleUrl: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/index.js'
  jsIpfsOpts: { /* advanced config */ }
})

The above should take care of adding <script> to the pagecontext before init with jsIpfsOpts is executed.

Ultimate fallback to latest js-ipfs

To make it even easier for beginners, ipfs-provider should default jsIpfsBundleUrl to https://unpkg.com/ipfs/dist/index.min.js when getJsIpfs and jsIpfsBundleUrl are absent.

TL;DR it should be possible to run:

const { ipfs, provider } = await getIpfs({ tryJsIpfs: true })

..and get the latest js-ipfs from NPM.

lidel avatar Jun 11 '19 11:06 lidel

can we self-boot it from IPFS somehow? 😄

parkan avatar Aug 12 '19 19:08 parkan

Kinda: the default jsIpfsBundleUrl (used when no explicit value is provided) could be an IPFS gateway URL

lidel avatar Aug 14 '19 12:08 lidel