缩小和连接JS / CSS文件,并使用精灵的图像仍然提供性能的好处,当使用HTTP / 2? [英] Does minifying and concatenating JS/CSS files, and using sprites for images still provide performance benefits when using HTTP/2?

查看:108
本文介绍了缩小和连接JS / CSS文件,并使用精灵的图像仍然提供性能的好处,当使用HTTP / 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用新的HTTP / 2协议,重复的HTTP请求对同一个服务器创建的开销已大大降低。

With the new HTTP/2 protocol the overhead created by repeated HTTP requests to the same server has been greatly reduced.

有了这一点,显着的性能优势缩小和连接JavaScript / CSS文件,并将图像合并到精灵?或者这些做法在使用HTTP / 2时不再有用吗?

With this in mind, are there still any significant performance advantages to minifying and concatenating JavaScript/CSS files, and combining images into sprites? Or are these practices no longer useful when HTTP/2 is being used?

推荐答案

HTTP / 2可减少其中某些操作的影响,但不会消除它们的影响

They're still useful. HTTP/2 reduces the impact of some of these practices, but it doesn't eliminate their impact.

一如既往。虽然HTTP / 2为消息头引入了新的压缩,这与缩小无关(这是关于消息体)。消息体的压缩算法是相同的,所以缩减节省了和以前一样多的带宽。

Minification remains as useful as ever. Although HTTP/2 introduces new compression for message headers, that has nothing to do with minification (which is about message bodies). The compression algorithms for message bodies are the same, so minification saves just as much bandwidth as it did before.

连接和sprites将比之前,但他们仍然会有一些影响。使用HTTP / 1下载多个文件而不是单个文件的最大问题实际上不是HTTP端问题,本身 是一些基于带宽的开销在单独请求每个文件,但它是相对的,当你完成一个文件,然后启动一个新的一个文件,并为每个文件重复这一点,基于时间的开销撕掉TCP / IP会话下载。

Concatenation and sprites will have less of an impact than before, but they will still have some impact. The biggest issue with downloading multiple files instead of a single file with HTTP/1 isn't actually an HTTP-side problem, per se: there is some bandwidth-based overhead in requesting each file individually, but it's dwarfed by the time-based overhead of tearing down the TCP/IP session when you're done with one file, then starting up a new one for the next, and repeating this for every file you want to download.

HTTP / 2的最大焦点是消除了基于时间的开销:HTTP / 1.1试图用流水线做这件事,但它没有赶上在浏览器(Presto是唯一的引擎,完全正确,Presto死了)。 HTTP / 2是另一种尝试,它改进了HTTP / 1.1的方法,同时使这种事情不是可选的,它是更成功的。 通过压缩标头,还可以消除在进行多个请求时产生的基于带宽的开销[em],但无法完全消除该开销,在下载多个文件时,这些请求仍然需要(作为单个TCP / IP会话的一部分,因此有较少的开销,但不是零)。

The biggest focus of HTTP/2 is eliminating that time-based overhead: HTTP/1.1 tried to do this with pipelining, but it didn't catch on in the browser (Presto is the only engine that got it completely right, and Presto is dead). HTTP/2 is another attempt, which improves on HTTP/1.1's methods while also making this kind of thing non-optional, and it stands to be more successful. It also eliminates some of the bandwidth-based overhead in making multiple requests, by compressing headers, but it cannot eliminate that overhead completely, and when downloading multiple files, those requests still have to be made (as part of a single TCP/IP session, so there is less overhead, but not zero). So while the impact of concatenating and spriting is proportionally smaller, there is still some impact, especially if you use many files.

另一件事情是,如果你使用多个文件,考虑,当谈到串联和spriting,是压缩。 类似类型的连续文件往往比单个文件压缩得更好,因为压缩算法可以利用连接的数据片段之间的相似性。 类似的原则适用于sprite :将相似的图片放在同一个文件的不同区域通常会产生较小的文件,因为图片的压缩可以利用不同区域的相似性。

Another thing to consider, when it comes to concatenation and spriting, is compression. Concatenated files of similar types tend to compress better than the individual files do, because the compression algorithm can exploit similarities between the concatenated pieces of data. A similar principle applies to sprites: putting similar images in different regions of the same file usually results in a smaller file, because the image's compression can exploit similarities in the different regions.

这篇关于缩小和连接JS / CSS文件,并使用精灵的图像仍然提供性能的好处,当使用HTTP / 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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