使用 base64 编码图像的优缺点

2022-01-21 00:00:00 image base64 html

我正在考虑为我正在开发的网站使用 base64 编码图像以优化加载时间.

I am thinking of using base64 encoded images for a site I am working on to optimize the load time.

无论如何,在开始之前,我想知道:这样做的优点和缺点是什么?

Anyways, before I start, I was wondering: what are the advantages and disadvantages of doing this?

目前,我没有看到任何缺点,但我也注意到它不是一种经常使用的技术,这让我怀疑我是否没有错过什么.

At the moment, I don't see any disadvantage but also I noticed that it is not a technique used very often and that makes me wonder if I didn't miss something.

谷歌搜索了这个主题后,我没有找到任何明确的东西,所以我决定在这里问.

After googleing the subject I didn't find anything clear so I decided to ask here.

推荐答案

它只对非常小的图像有用.Base64 编码文件比原始文件大.优点在于不必打开另一个连接并向服务器发出 HTTP 请求以获取图像.这种优势很快就会消失,因此只有大量非常小的单个图像才有优势.

It's only useful for very tiny images. Base64 encoded files are larger than the original. The advantage lies in not having to open another connection and make a HTTP request to the server for the image. This benefit is lost very quickly so there's only an advantage for large numbers of very tiny individual images.

相关文章