Nginx enable gzip compression js Invalid reason

Source: Internet
Author: User

Nginx enable Gzip is simple, only need to set a configuration file to complete, you can refer to the article nginx How to configure the gzip compression function. However, in the group often people mention that their website gzip compression although successful, but the detection of JS still no compression success, this is why? After my examination found that their gzip_types set the wrong cause, this article for people who meet the same situation to solve the problem.

nginx enable gzip compression JS Invalid

A group of friends mentioned in the group, he enabled the gzip compression of the site, through the Webmaster Tools gzip compression Detection to enable success, think of other files such as CSS, JS and so also compression success, but through further detection of various types of compression, found JS file and did not enable gzip compression, It made him very puzzled, somehow.

Figure 1:nginx Enable gzip compression JS invalid

Based on experience, I think maybe the reason is that the content of Gzip_types in his configuration file is not written right, so he asked him what the content of Gzip_types, he said it is set:

Figure 2:gzip_types Configuration

I carefully read his gzip_types content, and then look at the header information in Figure 1, found that the Content-type item "Application/javascript" did not appear in his gzip_types content, so I asked him to " Application/javascript "Write to his gzip_types, he according to my request to do, and then check, JS file gzip compression finally enabled success.

Figure 3:nginx Enable gzip compression JS success

Experience

The above case is that the group of friends did not add "Application/javascript" in the gzip_types, resulting in the JS file did not compress successfully, but after the discovery, some group of friends even joined the "Application/javascript" Also appear JS file no compression success condition, this is why? Originally, the JS type of the website "Content-type" content is not the same, nginx configuration gzip to the various types of files "content-type" content added to the line, do not add in can not be compressed.

Therefore, when found that the Nginx compression JS is not successful, you can first check the website JS header information, 1 as the detection (address: http://pagespeed.webkaka.com/youhua/gzip/), you can get the JS file " Content-type "content. Get its "content-type" content, and then look at the configuration file Gzip_types There is no such content, if not, join to solve the problem.

One-click detection of Web site types of files whether gzip enabled

It is important to note that the site is enabled for gzip compression and is not equal to the various types of files are enabled gzip compression, which is related to the proper setting. However, if you need to input a file to detect, it is a bit cumbersome. To this end, Kaka network can help you solve this problem, a key to detect the various types of Web site files are enabled gzip compression. Detection address is http://pagespeed.webkaka.com/, test results see:

Figure 4: One-click detection of Web site types of files whether Gzip enabled

Nginx-enabled gzip compression js Invalid reason

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.