Skip to content

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

Description

@lidel

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/ipfs@0.36.3/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions