Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Add document for running JS IPFS in the browser #2392

Merged
merged 21 commits into from
Dec 6, 2019
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
50ab2c2
Add document for running JS IPFS in the browser
tapaswenipathak Aug 26, 2019
60756b7
dht information line fixes
tapaswenipathak Oct 15, 2019
f4abde3
remove whitespaces
tapaswenipathak Oct 15, 2019
7ae4d96
js-ipfs introductory line fixes
tapaswenipathak Oct 15, 2019
42b41fd
i don't remember now
tapaswenipathak Oct 15, 2019
579f01d
separate tcp and delegated routing?
tapaswenipathak Oct 15, 2019
ba21205
Update doc/using-js-ipfs-in-the-browser.md
tapaswenipathak Oct 15, 2019
7dc4524
Update doc/using-js-ipfs-in-the-browser.md
tapaswenipathak Oct 15, 2019
3bbed60
Update doc/using-js-ipfs-in-the-browser.md
tapaswenipathak Oct 16, 2019
4e9b016
line item fixes
tapaswenipathak Oct 16, 2019
8035860
Merge branch 'ticket-2231' of github.com:tapaswenipathak/js-ipfs into…
tapaswenipathak Oct 16, 2019
873d147
english grammer fixes
tapaswenipathak Oct 16, 2019
0251e14
Update doc/using-js-ipfs-in-the-browser.md
tapaswenipathak Oct 16, 2019
8216eaa
Update doc/using-js-ipfs-in-the-browser.md
tapaswenipathak Oct 16, 2019
141127a
add example
tapaswenipathak Oct 16, 2019
015ea67
revert per the initial statement
tapaswenipathak Oct 16, 2019
1929d46
technical behavioral line item fixes
tapaswenipathak Oct 16, 2019
62e38c9
fix few more statements
tapaswenipathak Oct 16, 2019
df1e5b0
Merge branch 'ticket-2231' of github.com:tapaswenipathak/js-ipfs into…
tapaswenipathak Oct 16, 2019
256d900
Update using-js-ipfs-in-the-browser.md
lidel Oct 18, 2019
b603f18
Update using-js-ipfs-in-the-browser.md
lidel Oct 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions doc/using-js-ipfs-in-the-browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Using JS IPFS in The Browser
----------------------------

The document describes how you can use JS IPFS in the browser. JS IPFS is the
implementation of the IPFS protocal for browser. JS IPFS runs in a browser as a
service worked, a web extenstion and node.js. The document describes how you can
boost the speed and reduce the errors you face often because of limitation of
js-ipfs.

There are few different components for implementing JS IPFS in the browser. These
are webrtc and websocket-star which will make it easier for implemented JS IPFS
in the browser and boost the speed and reduce the errors.

You can find the information present for enabling webRTC support for js-ipfs in
the browser [here](https://github.com/ipfs/js-ipfs#how-to-enable-webrtc-support-for-js-ipfs-in-the-browser) and a different one is
implementing with webrtc-star, you can find information [here](https://github.com/ipfs/js-ipfs#is-there-a-more-stable-alternative-to-webrtc-star-that-offers-a-similar-functionality).

You can find information about running IPFS in the broswer [here](https://github.com/ipfs/js-ipfs#table-of-contents).

Getting Data From IPFS
-----------------------

Using Javascript in the browser

```js
const node = new IPFS()

node.once('ready', () => {
node.pipe('QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A', (err, data) => {
if (err) return console.error(err)

// convert Buffer back to string
console.log(data.toString())
})
})
```

JS IPFS Restriction in Web Browser
------------------------------------------

- There is no DHT in js-ipfs.

In browser a JS IPFS node is more restricted because of the same origin policy
that decrease the discover/connect with peers, external peers without rendezvous
and relay servers, delegating peer/content routing and preload servers for content
discoverablilty hard and erroneous even with swarm peers.

- Unable in opening TCP connections even if one sets up delegating routing the
issue will persist for connecting most of peers in the swarm as described a
little above.

- Connection with websocket ports should be adhering with [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) limitations.

JS IPFS Best Practices
----------------------

- Run in fedrated model.
- Configure nodes for using webrtc or websocket-star.
- Run independant instance as default one are under high load and YMMV.
- Make sure content you are implementing is cached in go-ipfs
- manually `pin` or preload CIDs of interest with `refs -r` beforehand.
- preload content on the fly using [preload](https://github.com/ipfs/js-ipfs#optionspreload) or
configuring [delgated routing](https://github.com/ipfs/js-ipfs#configuring-delegate-routers).
Here you will be using go-ipfs's API + nginx.

JS IPFS Examples
----------------

We have documented a lot of examples for implemented JS IPFS in the browser, you
can find them [here](https://github.com/ipfs/js-ipfs-http-client/tree/master/examples).