Compress JavaScript with gzip

浪尽此生 提交于 2019-12-13 04:53:36

问题


I ran Google PageSpeed Insights to optimize my site and it recommended archiving the numerous JavaScript files with gzip.

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?


回答1:


You can configure your web server to do the compression for you; in the case of Apache:

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



回答2:


I think they were referring to having static content compressed by the web server. The files themselves are the same, but you may need to do some configuration with whatever web server you have.

See this for more info.




回答3:


Most web servers (Apache, IIS, Node) support this feature internally or with plugins. You usually just have to enable it on the web server, you don't actually create the zip files or change anything manually. Take a look at http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/



来源:https://stackoverflow.com/questions/12593806/compress-javascript-with-gzip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!