Enable gzip compression CSS and JS in htaccess mode

Source: Internet
Author: User
Tags gz file gzip download
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.