The distributed web is a peer-to-peer (P2P) network that copies data across a network of computers and serves them in a decentralized way. Computers that participate in the P2P network are both clients and servers (nodes), and the network is considered resilient because content can remain available even if some nodes go offline.
The most popular distributed web solution is IPFS. IPFS is a P2P hypermedia protocol designed to make the web faster, safer, and more open. Content added via IPFS gets a distinct content identifier (CID) based on the file’s cryptographic hash. When people access the CID via a gateway or the IPFS protocol, it’s delivered by a node on the network instead of getting the content from a dedicated server. For example, this image is being served from the IPFS distributed web, and this is its unique hash:
Becoming an IPFS node is relatively easy. It can be run using a command-line interface (CLI) or as an app with a graphic user interface (GUI) on Windows, Mac, and Linux.
With the same Mac mini I use at my home to self-host WordPress with Cloudflare’s Automatic Platform Automation, I installed the macOS IPFS app. Once installed, the IPFS node runs in the background and adds an icon to the menu bar. Clicking on the icon displays a list of controls and options for managing the node.
The Status, Files, and Peers options will open the app’s window. From there, you can check the status of your node, add files, and change settings.
Adding a file is a simple process. Once it’s added, you can get a publicly accessible URL that uses the
ipfs.io gateway, and it will be distributed and served from other nodes in the background.
IPFS presents an excellent way to share files. It’s reminiscent of the basic file sharing feature of Droplr and CloudApp. You can add a file and then share the URL or CID for people to access it. The only thing missing feature is a built-in URL shortener.
Using IPFS to host a site with Cloudflare
IPFS restores the spirit and democratization of the internet by making it easy for anyone to share content online. Its existence is driven by certain ideals, with one of those being the desire for data permanence. Data permanence aims to fight censorship and keep a historical record of content for reference.
IPFS’ data permanence makes it impossible to edit content and virtually impossible to delete it. That means if you want to update your content, a new version of it will have to be added to IPFS, and it will be assigned a new CID. Data permanence creates a dilemma for someone who wants to use IPFS to host a site because each time they make a change, it creates a new CID.
Fortunately, there’s a workaround that enables you to use a domain name for the site and update the content without changing the URL.
Adding a site to IPFS
A site on IPFS can be a single page or have multiple pages. The main caveats are the site must be static, and its internal links and assets need to be relative to the top-level folder containing the site.
In most cases, sites, including single-page sites, will have assets like images. Therefore, I recommend putting everything in a folder. The single-page site I added to IPFS had four files.
Using the IPFS app, add the folder.
Next, pin the folder to specify that it’s important and shouldn’t be removed from your node.
To view the site, click on the Share link option.
Copy and paste the link into a browser. It should bring up the site that is now being served from your node and soon be propagated across the IPFS distributed web.
Configure Cloudflare DNS to point to IPFS CID
This step assumes the domain you want to use has already been added to Cloudflare. Also, Cloudflare has a document on how to connect your IPFS site if you need more details.
ipfs.io, Cloudflare has an IPFS gateway at
cloudflare-ipfs.com. Cloudflare’s gateway makes it possible to configure your DNS to associate an IPFS CID with a custom domain.
Before you create the DNS records, you will need the CID for the folder. In the IPFS app, click on Copy CID and then paste and save it in a text editor for later use.
In the DNS management tool on Cloudflare, add the following records:
- CNAME for
- TXT record for
_dnslink.your.websitewith the value
dnslink=/ipfs/<your_CID_here>(use the CID you copied earlier)
The site will now be available using your domain name. Keep in mind, it can take a few minutes before the site appears in a browser. You may also get a “CNAME Cross-User Banned” message, but it should be temporary.
Updating a site on IPFS and Cloudflare
Updating a site, even with minor updates, requires adding a completely new version of it to IPFS. Follow these steps to update it:
- Repeat the previous steps in “Adding a site to IPFS” and don’t unpin or delete the folder for the older version of the site (yet).
- Click on the Share link and view the updated site in a browser. Wait until everything displays correctly, including all assets like images, before proceeding to step 3.
- Copy the CID of the new folder.
- In Cloudflare’s DNS Management tool, change the CID for the TXT record to the new CID.
- View the site in a browser using your custom domain, and occasionally refresh until you can verify the new version of the site is appearing.
- Unpin and delete the older site folder from the IPFS app.
What kind of sites should you put on IPFS?
Because of the data permanence nature of IPFS and its limited capabilities, webmasters should carefully consider what they add to it. Here are some things to consider:
- Are there any concerns about your content being publicly accessible forever? If the answer is yes, you may want to avoid distributing it on IPFS.
- Is the site large, or does it require frequent editing? If either is true, using IPFS will create numerous permanent iterations of the site.
- Is the site dynamic? Sorry, only static sites will work on IPFS.
- Do you have content that you think could go viral, but you don’t have the budget to afford the server costs if it does? If item 1 isn’t a concern, then IPFS with Cloudflare may be the ideal solution.
I moved a site from a traditional hosting provider to IPFS and Cloudflare as part of my research for this article. The site I moved was etiquette.fyi, which I created in 2019 to respond to electric vehicle (EV) drivers that would park in charging spots but not charge. The site has an EV etiquette list and a PDF flyer that visitors can download, print, and put on EVs that shouldn’t be parked in a charging spot.
It was a perfect site to put on IPFS because I haven’t changed it since 2019, and I’m fine if it stays out there forever. And now that it’s on IPFS and using the Cloudflare Free plan, I don’t have to pay anything to keep it online. All I need to worry about is making sure I keep the domain name registered.