Skip to content

Commit 00b720f

Browse files
committed
refine examples and add note about websites
1 parent bc4bd62 commit 00b720f

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

docs/how-to/ipfs-in-web-apps.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ description: How to develop applications that use IPFS in web browsers, includin
55

66
# IPFS in web-applications and resource-constrained environments
77

8-
This guide covers the key operations of IPFS in the context of web applications, including addressing, retrieving, and providing.
8+
In this guide you will learn how to use IPFS in web applications, including addressing, retrieving, and providing.
99

10-
For demonstration purposes, this guide uses [Helia](https://github.com/ipfs/helia), the most actively maintained library for using IPFS on the web and is the recommended library for most use cases.
10+
In this guide, you will use [Helia](https://github.com/ipfs/helia), the most actively maintained TypeScript IPFS library for use on the web and the recommended library for most use cases.
1111

12-
## Challenges with IPFS on the Web
12+
> **Note:** this guide is focused solely on using IPFS for data within a web application. It does _not_ cover using IPFS for static website distribution with IPFS Gateways.
13+
14+
## Challenges with IPFS on the web
1315

1416
IPFS allows you to fetch data by CID from multiple providers without being reliant on a single authoritative server.
1517

16-
However, making all of this work on the Web is tricky due to networking constraints. Browsers impose many restrictions on Web apps, for example, opening TCP/UDP connections is not possible. Instead, Web apps are constrained to HTTP, WebSockets, WebRTC, and most recently WebTransport.
18+
However, making all of this work on the web is tricky due to networking constraints. Browsers impose many restrictions on web apps, for example, opening TCP/UDP connections is not possible. Instead, web apps are constrained to HTTP, WebSockets, WebRTC, and most recently WebTransport.
1719

18-
There are good reasons for this like security and resource management, but ultimately, it means that using IPFS on the Web is different to native binaries.
20+
There are good reasons for this like security and resource management, but ultimately, it means that using IPFS on the web is different to native binaries.
1921

2022
## Key IPFS operations: Addressing, Retrieving, and Providing
2123

@@ -25,8 +27,7 @@ As a developer, IPFS exposes three main operations for interacting with the netw
2527
- **Providing data by CID**: making data addressed by a CID retrievable by other peers, either by running a node or with a pinning service.
2628
- **Retrieving data by CID**: given a CID, IPFS finds providers (peers who share the block), connects to them, fetches the blocks, and verifies.
2729

28-
29-
## Addressing by CID
30+
## Addressing data by CID
3031

3132
As mentioned above, the first step in the [lifecycle of data in IPFS](../concepts/lifecycle.md) is to address it by CID.
3233

@@ -37,29 +38,22 @@ When addressing data by [CIDs](https://proto.school/anatomy-of-a-cid/03) you wil
3738
- [unixfs](../concepts/file-systems.md#unix-file-system-unixfs) for files and directories.
3839
- [dag-cbor](../concepts/glossary.md#dag-cbor) for json-like structured data with binary encoding. DAG-CBOR is an extension of CBOR that adds a "link" type for CIDs, allowing for the creation of interlinked CBOR objects (which can be used to form larger linked data structures).
3940

40-
As you can see, there are multiple ways to address data by CID.
41+
### CID Determinism
4142

42-
One important thing to note is that **the same data can result in different CIDs** depending on a number of factors, including the hash function, the multicodec you use, and the way you encode the data. **This is especially true for files**, where the same file, hash function and multicodec can still result in different CIDs depending on the different options that UnixFS supports. See the [forum discussion](https://discuss.ipfs.tech/t/should-we-profile-cids/18507) for more details and a possible solution.
43+
One important thing to note is that **the same data can result in different CIDs** depending on a number of factors, including the hash function, the multicodec you use, and the multicodec. **This is especially true for files**, where the same file, hash function and multicodec can still result in different CIDs depending on the different options that UnixFS supports. See the [forum discussion](https://discuss.ipfs.tech/t/should-we-profile-cids/18507) for more details.
4344

4445
### Example: Addressing an object by CID with dag-cbor
4546

4647
For example, to address an object by CID with the `dag-cbor` multicodec and `sha2-256` hash function, you can use the following code using [Helia](https://github.com/ipfs/helia):
4748

48-
```ts
49-
import { createHelia } from 'helia'
50-
import { dagCbor } from '@helia/dag-cbor'
51-
52-
const helia = await createHelia()
53-
const d = dagCbor(helia)
54-
const cid = await d.add({ hello: 'world' })
55-
56-
console.info(cid)
57-
// CID(bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae)
58-
```
49+
<iframe height="300" style="width: 100%;" scrolling="no" title="Addressing an object by CID with Helia and dag-cbor" src="https://codepen.io/2color/embed/xbKpJKx?default-tab=js%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
50+
See the Pen <a href="https://codepen.io/2color/pen/xbKpJKx">
51+
Addressing an object by CID with Helia and dag-cbor</a> by Daniel Norman (<a href="https://codepen.io/2color">@2color</a>)
52+
</iframe>
5953

6054
### Example: Addressing a file by CID with unixfs
6155

62-
<iframe height="500" style="width: 100%;" scrolling="no" title="Addressing an image by CID with Helia and UnixFS" src="https://codepen.io/2color/embed/zxONqPj?default-tab=html%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
56+
<iframe height="500" style="width: 100%;" scrolling="no" title="Addressing an image by CID with Helia and UnixFS" src="https://codepen.io/2color/embed/zxONqPj?default-tab=js%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
6357
See the Pen <a href="https://codepen.io/2color/pen/zxONqPj">
6458
Addressing an image by CID with Helia and UnixFS</a> by Daniel Norman (<a href="https://codepen.io/2color">@2color</a>)
6559
</iframe>
@@ -72,7 +66,7 @@ If you want to data to be retrievable by other peers on [Mainnet](../concepts/gl
7266

7367
### You probably don't want to provide data from a browser
7468

75-
Browsers make for lousy servers. It's difficult to make a Web page "dialable", i.e. allow network incoming connections from other computers. There's one exception, namely WebRTC, however, it has many caveats.
69+
Browsers make for lousy servers. It's difficult to make a Web page a server, i.e. allow network incoming connections from other computers. There's one exception, namely WebRTC, however, it has many caveats.
7670

7771
For this reason, you should almost never count on providing data from a browser to work.
7872

@@ -82,12 +76,11 @@ Instead, you should provide data from a long-running server that runs reliably a
8276

8377
CAR files offer a serialized representation of content-addressed resources in one single concatenated stream, alongside a header that describes that content. This makes them a great way to store content-addressed data in a way that is easy to transport and store.
8478

85-
8679
## Retrieval
8780

8881
### With Verified-fetch
8982

90-
<iframe height="500" style="width: 100%;" scrolling="no" title="Fetch an image on IPFS Mainnet @helia/verified-fetch" src="https://codepen.io/2color/embed/QWXKZGx?default-tab=html%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
83+
<iframe height="500" style="width: 100%;" scrolling="no" title="Fetch an image on IPFS Mainnet @helia/verified-fetch" src="https://codepen.io/2color/embed/QWXKZGx?default-tab=js%2Cresult" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
9184
See the Pen <a href="https://codepen.io/2color/pen/QWXKZGx">
92-
Fetch an image on IPFS Mainnet @helia/verified-fetch</a> by Daniel Norman (<a href="https://codepen.io/2color">@2color</a>)
85+
Fetch an image on IPFS Mainnet @helia/verified-fetch</a> by Daniel Norman
9386
</iframe>

0 commit comments

Comments
 (0)