Page 1 of 3

nginx wordpress js with gzip?

Posted: Tue Jun 07, 2016 3:58 pm
by hcjsy
Hi,
Can someone explain to my why if I use gzipwtf.com gtmetrix.com or the google web one, that it comes back saying that JS files are not gziped on my website?

however if I run a curl command

Code: Select all

 curl -H "Accept-Encoding: gzip" -I http://wordpress.highlands.ac.uk/wp-includes/js/wp-embed.min.js
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Jun 2016 15:36:12 GMT
Content-Type: application/javascript
Last-Modified: Tue, 07 Jun 2016 09:43:36 GMT
Connection: keep-alive
Keep-Alive: timeout=60
Vary: Accept-Encoding
ETag: W/"57569748-57b"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Encoding: gzip
it says it is working for JS?

Re: nginx wordpress js with gzip?

Posted: Tue Jun 07, 2016 4:15 pm
by SS88
hcjsy wrote:Hi,
Can someone explain to my why if I use gzipwtf.com gtmetrix.com or the google web one, that it comes back saying that JS files are not gziped on my website?

however if I run a curl command

Code: Select all

 curl -H "Accept-Encoding: gzip" -I http://wordpress.highlands.ac.uk/wp-includes/js/wp-embed.min.js
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 07 Jun 2016 15:36:12 GMT
Content-Type: application/javascript
Last-Modified: Tue, 07 Jun 2016 09:43:36 GMT
Connection: keep-alive
Keep-Alive: timeout=60
Vary: Accept-Encoding
ETag: W/"57569748-57b"
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
Content-Encoding: gzip
it says it is working for JS?
What's your configuration like because none of your .JS files are gzipped (or so it says).

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 7:03 am
by hcjsy
gzip bit from : /etc/nginx/nginx.conf

Code: Select all

    # Compression
    gzip                on;
    gzip_comp_level     9;
    gzip_min_length     512;
    gzip_buffers        8 64k;
    gzip_types          gzip_types text/plain text/css application/json application/javascript text/xml application/xml
                        application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf
                        font/opentype image/svg+xml image/x-icon;
    gzip_vary           on;
    gzip_disable        "MSIE [1-6]\.(?!.*SV1)";
    gzip_proxied        any;



Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 11:54 am
by SS88
Was it a copy / paste job?

Please see bolded error:

gzip_types gzip_types text/plain text/css application/json application/javascript text/xml application/xml
application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf
font/opentype image/svg+xml image/x-icon;

You may also want to add in application/x-javascript

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 11:59 am
by hcjsy
apologies the config doesnt have the duplicate gzip_types, I will add application/x-javascript , but that isn't in the mime types file so not sure it will do anything?

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 12:00 pm
by hcjsy
Also the website is using web template hosting and proxy template hosting

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 12:04 pm
by SS88
application/javascript is the "standard" and both others are obsolete but if you can add both to the mime types and test again it may help.

Also take a look in /home/<USER>/conf/web for nginx.conf files as a setting may be overriding it (no need to unless you have changed something in there) as the default proxy template is OK.

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 12:05 pm
by hcjsy
I've just ran the test again and still coming back with saying gzip not for js :(

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 12:11 pm
by SS88
If you add it directly in server { }

/home/<USER>/conf/web/nginx.conf like so:

Code: Select all

server {

listen      blah;
server_name blah;
root        /home/blah/web/blah/public_html

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/js text/javascript application/javascript application/x-javascript;
}
Does that work!?

Re: nginx wordpress js with gzip?

Posted: Wed Jun 08, 2016 12:11 pm
by hcjsy
Thanks for the suggestions.
SS88 wrote:application/javascript is the "standard" and both others are obsolete but if you can add both to the mime types and test again it may help.
nginx: [warn] duplicate extension "js", content type: "application/x-javascript", previous content type: "application/javascript" in /etc/nginx/mime.types:9
nginx: [warn] duplicate extension "js", content type: "application/x-javascript", previous content type: "application/javascript" in /etc/nginx/mime.types:9

but still the same :(
SS88 wrote:Also take a look in /home/<USER>/conf/web for nginx.conf files as a setting may be overriding it (no need to unless you have changed something in there) as the default proxy template is OK.
have checked these, but no reference to gzip in them.