Batteries-included: load js-ipfs from CDN when no instance is provided
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.
can we self-boot it from IPFS somehow? 😄
Kinda: the default jsIpfsBundleUrl (used when no explicit value is provided)
could be an IPFS gateway URL