91

All JavaScript files are not compressed by nginx gzip.

CSS files are working.

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;

3 Answers 3

177

Change this line:

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

To be 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 your list of gzip types.

There are also more details—and a more expansive list of gzip types—in the answer posted here.

0
8

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

text/javascript (Obsolete): JavaScript; Defined in and made obsolete in RFC 4329 in order to discourage its usage in favor of application/javascript. However, text/javascript is allowed in HTML 4 and 5 and, unlike application/javascript, has cross-browser support. The "type" attribute of the tag in HTML5 is optional and there is no need to use it at all since all browsers have always assumed the correct default (even in HTML 4 where it was required by the specification).

From this thread: text/javascript vs application/javascript

So the gzip module of nginx is simply built against previous standards, and apparently doesn't properly process the application/javascript mime type.

2
  • 1
    this was the only working solution text/javascript js;
    – Salem
    Commented Nov 5, 2017 at 16:45
  • I face the same issue again and i just add application/javascript to gzip_types
    – Salem
    Commented Aug 24, 2019 at 20:52
4

Work for me (nginx):

gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml/javascript;
1
  • 1
    That helped me to get completely rid of the "compress text" message from Lighthouse. Before I still had trouble with those JS & CSS-Files that had parameters at it like jquery.min.js?ver=2.7.0-wc.6.7.0. But this fully solved it for me. Thanks a lot @iqmaker!
    – suther
    Commented Nov 9, 2022 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.