admin avatar

Apache 格式化网页HTML源码的方法

🕗 by admin





Apache 格式化网页HTML源码的方法

即是把网页源代码中多余的空格删除,

减小网页传输数据,加速网页传输

把下面代码添加到网站根目录的 .htaccess文件中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

自行修改相关代码实现一些资源合理的格式化,比如js文件,有时候过度压缩会影响js功能,上面代码已经开启了gzip 压缩。





💘 相关文章





写一条评论

Based on Golang + fastHTTP + sdb | go1.18.1 Processed in 2ms