The function of compressing CSS and JS into gzip has been tried before. it is good. But the following one. the htaccess static and manual compression method is troublesome but super efficient, and has good compatibility and better performance. it can read the cached js and css compressed version gz to speed up site access. Em comes with the gzip compression function, but it is still collected first
The function of compressing CSS and JS into gzip has been tried before. it is good. However, the following. htaccess static manual compression method is troublesome but super efficient,
It also has good compatibility and a better feeling. it can read the cached js and css compressed version gz to speed up site access.
Em comes with the gzip compression function, but it is collected first and used by other sites later.
The procedure is as follows:
Upload the Gzip. php file to the root directory of the website, that is, the/public_html/folder;
Modify the. htaccess file of the website and add the following statement:
12345678910111213141516171819202122232425262728293031 |
AddEncoding gzip. js ForceType application/x-javascript
AddEncoding gzip. css ForceType text/css
RewriteEngine On RewriteBase/# wordpress static website support. if you set it, there will be the following three lines of RewriteCond % {REQUEST_FILENAME }! -F RewriteCond % {REQUEST_FILENAME }! -D RewriteRule. /index. php [L] # When I read css and js, I will re-import it to gzip. php RewriteRule (. *. css $ |. *. js $) gzip. php? $1 [L] indicates that the RewriteCond % {HTTP: Accept-encoding} gzip RewriteCond returns request_filename=.gz-f RewriteRule ^ (. * When .css expires 1.css.gz [L, QSA] expires, re-import RewriteCond % {HTTP: Accept-encoding} gzip RewriteCond into request_filename=.gz-f RewriteRule ^ (. *). js release 1.js.gz [L, QSA]
|
Then browse your website to generate the gz file for CSS and JS. Note that if CSS and JS files do not generate the gz file after browsing,
Note that the upper-layer folder attribute of the folder where CSS and JS are located is modified to 777.
Finally, rewrite. htaccess again and comment out or delete the following code.
1 RewriteRule (. *. css $ |. *. js $) gzip. php? $1 [L]
Note: If you want to modify CSS and JS in the future, you need to restore the code and redo the previous steps.The method is troublesome, but the effect is good.
The following shows how to test whether the website enables gzip compression:
Http://tool.chinaz.com/Gzips/Default.aspx
Gzip download:Http://u.115.com/file/dnjn6dd4