Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lidel opened this issue Jun 11, 2019 · 2 comments
Open

Comments

@lidel
Copy link
Member

lidel commented Jun 11, 2019

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.

@parkan
Copy link

parkan commented Aug 12, 2019

can we self-boot it from IPFS somehow? 😄

@lidel
Copy link
Member Author

lidel commented Aug 14, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants