什么是更快地加载图像的最佳方式,.png/.jpg 格式或数据 URI 方案?

What is the best way to load an image faster, either the .png/.jpg format or the data URI scheme?

加载 数据 URI 格式的图像是否会使其在页面中加载得更快? 例如:background: url("data:image/jpg;base64,/someImageData")

还是以常见的 .jpg 或 .png 格式加载速度更快? 例如:background: url("wallpaper.jpg")

渲染图像所需的时间将相同,但加载所需的时间可能不同。与通过 url():

对图像进行 link 相比,对图像进行 Base64 编码使其大约 37% larger

Very roughly, the final size of Base64-encoded binary data is equal to 1.37 times the original data size

然而,虽然图像更大并且需要更多字节来下载,但您可以节省与服务器对话的时间以使用 url() 方法获取图像。无法确定哪个加载速度更快 - 这将取决于用户的连接。请参阅 this article 了解何时最好使用 base64 编码图像。

data-uri 的大小大约增加了 37%,但还有更重要的一点:

On Mobile, Data URIs are 6x Slower than Source Linking (New Research)

所以要小心这个。并且,as stated on caniuse.com,IE < 9 有显着的数据总量限制。