展开原文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/).