NGINX gzip does not compress JavaScript files

All JavaScript files are not compressed by nginx gzip.

CSS files work.

In my nginx.conf , I have the following lines:

 gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_proxied any; gzip_buffers 16 8k; gzip_types text/plain application/x-javascript text/xml text/css; gzip_vary on; 
+49
nginx
May 29 '14 at 17:51
source share
2 answers

Change this line:

 gzip_types text/plain application/x-javascript text/xml text/css; 

For this:

 gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; 

Note the addition of application/javascript and text/javascript to the gzip type list.

There is also more detailed information and a more extensive list of gzip types - in the answer here .

+108
May 29 '14 at 17:56
source share
— -

This is interesting because the best, old standard mime type for javascript in the browser is actually text / javascript. And if you configure this, in /etc/nginx/mime.types it works.

text / javascript (Deprecated): JavaScript; Defined and deprecated in RFC 4329 to discourage its use in favor of the application / javascript. However, / javascript text is allowed in HTML 4 and 5 and, unlike the / javascript application, supports cross-browser. The "type" attribute of a tag in HTML5 is optional and should not be used at all, since all browsers always accepted the correct default values ​​(even in HTML 4, where this was required by the specification).

From this topic: text / javascript vs application / javascript

Thus, the nginx gzip module is simply built against previous standards and apparently does not correctly handle the mime type of the application / javascript.

+3
Nov 18 '15 at 10:43
source share



All Articles