在 Discourse 中使用 Rust、WebAssembly 和 MozJPEG 实现更快(且更小)的上传
As of a few weeks ago, image uploads in Discourse are faster AND smaller thanks to a technique that compresses and optimizes the images clientside before they are uploaded. This blog post will describe how this feature works and how we implemented it in Discourse.
就在几周前,由于采用了一种在图像上传之前就在客户端进行压缩和优化的技术,Discourse 中的图像上传变得更快且体积更小。这篇博客文章将描述该功能的工作原理以及我们如何在 Discourse 中实现它。
Introduction
简介
While Discourse, and forums in general, are mainly about ¶ paragraphs of text, the discourse on the internet is increasingly composed of media. Pictures have become a major part of user posts. It's also worth mentioning that in the 8 years since we started Discourse, smartphone cameras became ubiquitous and can take great pictures in an instant.
虽然 Discourse 以及一般的论坛主要关注 ¶ 段落文本,但互联网上的 讨论 正越来越多地由媒体组成。图片已成为用户帖子的重要组成部分。值得一提的是,在我们启动 Discourse 的 8 年里,智能手机摄像头变得无处不在,并且可以瞬间拍出出色的照片。
Because of all that, very early into the project we received feature requests about Optimizing images before uploading. This is motivated by staff looking to make it easy for their users to share pictures while being mindful of the time it takes to upload files from spotty mobile connections.
正因如此,在项目初期我们就收到了关于上传前优化图像的功能请求。这主要是工作人员希望让用户更轻松地分享图片,同时考虑到在信号不佳的移动网络下上传文件所需的时间。
One of the leading experiments of client-side image compression is the Squoosh.app by the cool people at Google Chrome Labs. It was first announced in this talk and it was definitive proof that it was possible to get quality image compression right on the client side by leveraging new browser features like WebAssembly.
客户端图像压缩领域的领先实验之一是由 Google Chrome Labs 的优秀团队推出的 Squoosh.app。它首次在这篇演讲中公布,并确凿地证明了通过利用 WebAssembly 等新的浏览器特性,完全可以在客户端实现高质量的图像压缩。
Our new image optimization pipeline
我们全新的图像优化流水线
When you click on the upload button while composing a post in Discourse, we open the Operating System file picker and then you can select one or more files to add to your post. If an image is detected, the new feature kicks in and performs the optimization just-in-time before uploading the file to the server.
当你在 Disco...