浏览器是直接加载二进制图片更快还是加载base64编码的图片更快?

夜很慌我很方
  • 41

浏览器是直接加载二进制图片更快还是加载base64编码的图片更快?哪个效率更高?

例如:

<img src=" https://sf-static.b0.upaiyun.com/v-57e4f057/global/img/user-256.png" />

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAADAFBMVEUAAAAAAACAgIBVVVWAgICZmZmAgICSkpKAgICOjo6ZmZmLi4uVlZWJiYmSkpKZmZmPj4+WlpaOjo6UlJSZmZmSkpKXl5eQkJCVlZWZmZmTk5OXl5eSkpKVlZWZmZmUlJSXl5eTk5OWlpaZmZmVlZWYmJiUlJSWlpaZmZmVlZWYmJiUlJSXl5eZmZmWlpaYmJiVlZWXl5eZmZmWlpaYmJiVlZWXl5eZmZmWlpaYmJiVlZWXl5eZmZmWlpaYmJiWlpaXl5eZmZmXl5eYmJiWlpaYmJiZmZmXl5eYmJiWlpaYmJiZmZmXl5eYmJiWlpaYmJiZmZmXl5eYmJiXl5eYmJiZmZmXl5eYmJiXl5eYmJiZmZmXl5eYmJiXl5eYmJiZmZmXl5eYmJiXl5eYmJiZmZmXl5eZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmXl5eYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiYmJiZmZmYmJiZmZmYmJiZmZmZmZmYmJiZmZmY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HYxSyYHVSiMKGAGKZRRlQ5hHEcg8rLIZFWwrboGMqhdawmswKFyKWJygDyjyKWF5nha2wOInCt9AxjUJLWO1khZcRy2zKgDKPI5YfWCGUgEqtKXwLHdMpZMIiKcwKuxHLHMqAMtMQyzFWSkallhS2Q8dMCi1g0ZIW6YhhLmVAmRmIIYUWyajUgsJ26JhFoRksTqfF6YhhLmVAmZmIoRktklGpKYUd0DGbQlNYdKXFxYhhDmVAmScQQwdapKBSBoUd0DGHQhNYdKXFEMQwmzKgzBzEkEuLFFRKp/AddMylkAGLbrS4GzHMogwo8yRiyKFFHViU8nc7oWMehQaw6E6LKYhhJmX+Az5+glXr/+1CAAAAAElFTkSuQmCC"/>
回复
阅读 7.5k
5 个回答

如果仅从加载速度上来说,小图片使用base64毫无疑问会更快,因为可以减少一次http请求,但是如果图片较大,转换后的base64会更大,浏览器解析需要更长的时间,有可能会造成页面阻塞,效率上应该不如直接放图片,而且使用base64无法缓存(除非直接缓存整个文件)。
总结:分场景使用,小图标/icon使用base64效率一定更高,大图片使用默认方式加载,可以充分利用缓存,渲染解析效率高。
前端开发中,使用base64图片的弊端是什么?

base64 因为不产生http请求 。

BASE64如下:

通过请求如下:

这里仅做抛砖引玉的作用,具体各个尺寸的比较就交给各位了。

如果你指的二进制图片是这种形式的话:

<img src=" https://sf-static.b0.upaiyun.com/v-57e4f057/global/img/user-256.png" />

那还是base64比较快,因为 img 标签需要额外一次HTTP链接去获取显示的图片,显然两者所花的时间不是一个数量级的

你知道吗?

宣传栏