展開原文In this series we are covering projects that explore what is possible when the web becomes decentralized or distributed. These projects aren’t affiliated with Mozilla, and some of them rewrite the rules of how we think about a web browser. What they have in common: These projects are open source, and open for participation, and share Mozilla’s mission to keep the web open and accessible for all.
在這個系列中,咱們會講到一些正在嘗試探索在 Web 變爲去中心化或分佈式的時候存在哪些可能性的項目,這些項目不附屬於 Mozilla,其中一些項目還從新定義了咱們對 web 瀏覽器的認識。他們都有共同點:這些項目都是開源的,開放參與的,而且和 Mozilla 」keep the web open and accessible for all (讓 Web 對全部人保持開放和可訪問)「 的宗旨一致。web
展開原文So far we’ve covered distributed social feeds and sharing files in a decentralized way. with some new tools for developers. Today we’d like to introduce something a bit different: Imagine what an *entire browser experience* would be like if the web was distributed… Beaker browser does exactly this! Beaker is a big vision from a team who are proving out the distributed web from top to bottom. Please enjoy this post from Beaker co-creator Tara Vancil. – Dietrich Ayala
展開原文We work on Beaker because publishing and sharing is core to the Web’s ethos, yet to publish your own website or even just share a document, you need to know how to run a server, or be able to pay someone to do it for you.
Web 的基礎就是發佈和分享,如今若是你想發佈屬於本身的網站或者分享一些文檔,你仍然須要懂得如何運營一臺服務器,或者具有因僱人幫你作這些而支付報酬的能力。瀏覽器
So we asked ourselves, 「What if you could share a website directly from your browser?」服務器
因此咱們開始思考「是否咱們能夠僅在瀏覽器裏就能搭建一個網站?」網絡
展開原文 Peer-to-peer protocols like `dat://` make it possible for regular user devices to host content, so we use `dat://` in Beaker to enable publishing from the browser, where instead of using a server, a website’s author and its visitors help host its files. It’s kind of like BitTorrent, but for websites!
展開原文 `dat://` websites are addressed with a public key as the URL, and each piece of data added to a `dat://` website is appended to a signed log. Visitors to a `dat://` website find each other with a tracker or [DHT](https://en.wikipedia.org/wiki/Distributed_hash_table), then sync the data between each other, acting both as downloaders and uploaders, and checking that the data hasn’t been tampered with in transit.
展開原文 At its core, a `dat://` website isn’t much different than an https:// website — it’s a collection of files and folders that a browser interprets according to Web standards. But `dat://` websites are special in Beaker because we’ve added [peer-to-peer Web APIs](https://beakerbrowser.com/docs/apis) so developers can do things like read, write, and watch `dat://` files and build peer-to-peer Web apps.
從本質上講,一個dat://網站和一個 https:// 網站沒有什麼不一樣——都是瀏覽器按照 Web 的系列標準來解釋一系列文件及目錄的形式。可是 dat:// 網站特殊的地方就在於 Beaker,由於咱們爲其附加了「點對對 Web 接口」, 以便開發者能夠進行讀取、寫入及監測 dat:// 文件從而構建出點對點 Web 應用。
建立一個 P2P 網站
展開原文Beaker makes it easy for anyone to create a new `dat://` website with one click (see our [tour](https://beakerbrowser.com/docs/tour)). If you’re familiar with HTML, CSS, or JavaScript (even just a little bit!) then you’re ready to publish your first `dat://` website.
展開原文This example shows a website editing *itself* to create and save a new JSON file. While this example is contrived, it demonstrates a common pattern for storing data, user profiles, etc. in a `dat://` website—instead of application data being sent away to a server, it can be stored in the website itself!
// index.js 文件// first get an instance of the website's files// 首先實例化該網站的文件集合對象var files = new DatArchive(window.location)
document.getElementById('create-json-button').addEventListener('click', saveMessage)
asyncfunctionsaveMessage () {
var timestamp = Date.now()
var filename = timestamp + '.json'var content = {
timestamp,
message: document.getElementById('message').value
}
// write the message to a JSON file// this file can be read later using the DatArchive.readFile API// 將消息寫入一個 JSON 文件// 這個文件在以後還能夠經過 DataArchive.readFile 接口進行讀取await files.writeFile(filename, JSON.stringify(content))
}
複製代碼
更多信息
展開原文 We’re always excited to see what people build with `dat://` and Beaker. We especially love seeing when someone builds a personal site or blog, or when they experiment with Beaker’s APIs to build an app.
展開原文 Tara is the co-creator of the [Beaker browser](https://beakerbrowser.com/). Previously she worked at Cloudflare and participated in [the Recurse Center](https://recurse.com/).