Apache如何设置对js、css等文本资源进行gzip压缩传输?

Apache如果不对js、css等文本资源进行压缩传输,会导致网页加载速度变慢,而且还会多占带宽。因此我们需要设置Apache开启gzip压缩,大幅度降低文本资源的传输大小。设置步骤如下:

  1. 确认是否已经加载了mod_deflate和mod_headers这两个模块:

LoadModule deflate_module modules/mod_deflate.so

LoadModule headers_module modules/mod_headers.so

确保http.conf文件中,这两行的前面没有#号。

  1. 在配置文件中添加以下内容:

AddOutputFilter DEFLATE html htm php txt xml css js

或者

AddOutputFilterByType DEFLATE application/x-javascript text/html text/plain text/xml text/css

  1. 保存设置,重启apache:

apachectl graceful

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注