如何更快的是它使用内联/ BASE64图像的网站不仅仅是连接到硬盘文件? [英] How much faster is it to use inline/base64 images for a web site than just linking to the hard file?

查看:127
本文介绍了如何更快的是它使用内联/ BASE64图像的网站不仅仅是连接到硬盘文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更快的是它使用一个base64 /线来显示图像比而不是简单地连接到硬盘文件的服务器上?

How much faster is it to use a base64/line to display images than opposed to simply linking to the hard file on the server?

url(data:image/png;base64,.......)

我一直没能找到任何类型的性能指标这一点。

I haven't been able to find any type of performance metrics on this.

我有几个顾虑:


  • 您不再获得高速缓存的好处

  • 是不是一个base64大小比什么是PNG / JPEG文件的大小?
  • 系统LOT较大
  • You no longer gain the benefit of caching
  • Isn't a base64 A LOT larger in size than what a PNG/JPEG file size?

让我们来定义更快,如:它需要一个用户看到一个完整的呈现的HTML网页时

推荐答案

更快是一个很难的事情来回答,因为有许多可能的跨pretations和情况:

'Faster' is a hard thing to answer because there are many possible interpretations and situations:

Base64编码将通过第三扩大图像,这将增加的带宽利用率。另一方面,包括它在文件中将会移除另一GET往返到服务器。因此,具有很大的吞吐量,时延差(如卫星连接互联网)的管道可能会比如果你使用不同的图像文件更快的加载使用内嵌的图片页面。即使在我的(农村,慢)DSL线路,需要多次往返的网站需要更长的时间比那些只是比较大,但需要只有少数的GET。

Base64 encoding will expand the image by a third, which will increase bandwidth utilization. On the other hand, including it in the file will remove another GET round trip to the server. So, a pipe with great throughput but poor latency (such as a satellite internet connection) will likely load a page with inlined images faster than if you were using distinct image files. Even on my (rural, slow) DSL line, sites that require many round trips take a lot longer to load than those that are just relatively large but require only a few GETs.

如果你从每个请求的源文件的base64编码,您将使用更多的CPU,颠簸数据缓存等,这些可能会伤害您的服务器响应时间。 (当然你也可以随时使用memcached的或者这样来解决这个问题)。

If you do the base64 encoding from the source files with each request, you'll be using up more CPU, thrashing your data caches, etc, which might hurt your servers response time. (Of course you can always use memcached or such to resolve that problem).

这样做当然prevent大多数形式的缓存,如果在查看图像往往可能伤害了很多这种意志 - 比如,所显示的每个页面上的一个标志,这可能通常由浏览器缓存(或一个代理缓存像鱿鱼或其他),并要求每月一次。它也将prevent了很多很多的优化Web服务器有服务使用内核API喜欢的sendfile静态文件(2)。

Doing this will of course prevent most forms of caching, which could hurt a lot if the image is viewed often - say, a logo that is displayed on every page, which could normally be cached by the browser (or a proxy cache like squid or whatever) and requested once a month. It will also prevent the many many optimizations web servers have for serving static files using kernel APIs like sendfile(2).

基本上,这样做将有助于在某些情况下,和别人伤害。您需要确定哪些情况对你很重要,你可以真正弄清楚之前,如果这对你是一个有价值的伎俩。

Basically, doing this will help in certain situations, and hurt in others. You need to identify which situations are important to you before you can really figure out if this is a worthwhile trick for you.

这篇关于如何更快的是它使用内联/ BASE64图像的网站不仅仅是连接到硬盘文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆