什么是angular 2中的bundle.js.gz文件? [英] What is bundle.js.gz file in angular 2?

查看:95
本文介绍了什么是angular 2中的bundle.js.gz文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为应用程序使用ng-cli.当我运行ng build --prod时,我得到了两个文件main.budle.js& main.bundle.js.gz.什么是第二个&它有什么好处?

I am using ng-cli for my application. when i run ng build --prod, i got two files main.budle.js & main.bundle.js.gz. what is the second one & what is the benefit of it?

推荐答案

服务器和客户端之间的HTTP传输几乎总是使用压缩.在大多数情况下,这是gzip.

HTTP transfer between server and client almost always uses compression. In most cases this is gzip.

对于传输时间而言,重要的不是bundle.js的大小,而是bundle.js.gz的大小,因为内容实际上总是以其gzip压缩形式发送.

So what matters for transfer times is not the size of your bundle.js but the size of bundle.js.gz as content is practically always sent in its gzip compressed form.

当请求bundle.js时,服务器会即时对其进行gzip压缩,然后将其放在网上.因此,对每个请求都运行gzip,这对于静态内容而言效率低下.

When bundle.js is requested, the server gzips it on the fly and puts it on the wire. So gzip is run on every request, which is inefficient for static content.

gzip的性能也会随着压缩级别的显着降低(查看这篇文章).尽可能地使用最高压缩级别并不是很有效. 正确配置的Web服务器将在请求bundle.js的压缩版本时发送bundle.js.gz,因此您可以使用gzip可以提供的最高压缩级别.

Also gzip's performance drops significantly with the level of compression (check out this article). Using the highest compression level possible isn't efficient if at all possible on-the-fly. A properly configured webserver would send bundle.js.gz when a gzipped version of bundle.js is requested, so you could use the highest compression level gzip can provide.

在我看来,除非您的服务器主要提供可以提前压缩的静态内容,否则它的性能优势是微不足道的.对于小型应用程序,由于静态内容和API是在同一台计算机上提供的,因此实际上不会产生任何影响.

In my opinion, the performance bonus of this is negligible unless your server mainly provides static content that can be compressed ahead-of-time. For a small application, with static content and API being served from the same machine, there should be practically no impact.

这篇关于什么是angular 2中的bundle.js.gz文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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