admin avatar

Apache minify web page HTML source method

🕞 by admin

Apache format web page HTML source method

This is to remove the extra spaces in the source code of the webpage.

Reduce web page transmission data and speed up web page transmission

Add the following code to the.htaccess file in the root directory of the website

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>
Modify the relevant code by yourself to achieve reasonable formatting of some resources, such as js files. Sometimes excessive compression will affect js functions. The above code has already enabled gzip compression.

💘 相关文章

写一条评论