简体   繁体   English

用gzip压缩JavaScript

[英]Compress JavaScript with gzip

I ran Google PageSpeed Insights to optimize my site and it recommended archiving the numerous JavaScript files with gzip. 我运行Google PageSpeed Insights来优化我的网站,它建议使用gzip归档大量JavaScript文件。

How does this work? 这是如何运作的? How are the files imported/included as an archive? 如何将文件导入/包含为归档文件? Can they all be inside one big archive, or should they be individual archives? 它们是否都可以放在一个大档案中,还是应该是单个档案?

I think they were referring to having static content compressed by the web server. 我认为他们指的是由Web服务器压缩静态内容。 The files themselves are the same, but you may need to do some configuration with whatever web server you have. 文件本身是相同的,但是您可能需要对拥有的任何Web服务器进行一些配置。

See this for more info. 请参阅以获取更多信息。

You can configure your web server to do the compression for you; 您可以配置Web服务器来为您进行压缩。 in the case of Apache : Apache而言

AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Most web servers (Apache, IIS, Node) support this feature internally or with plugins. 大多数Web服务器(Apache,IIS,Node)在内部或通过插件支持此功能。 You usually just have to enable it on the web server, you don't actually create the zip files or change anything manually. 通常,您只需要在Web服务器上启用它,实际上就不需要创建zip文件或手动更改任何内容。 Take a look at http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/ 看看http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM