Compressing Javascript files.
I am new to Linode and enjoying having full control on the slice. Lot to learn nd its fun!!
I was trying to figure out why my gzip compression of JS files does not work.
curl –head
HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Mon, 13 Dec 2010 10:34:27 GMT
Content-Type: application/x-javascript
Content-Length: 181666
Last-Modified: Sun, 12 Dec 2010 23:04:20 GMT
Connection: keep-alive
Vary: Accept-Encoding
Accept-Ranges: bytes
In my /opt/nginx/conf/nginx.conf, I have:
gzip on;
gziphttpversion 1.1;
gzip_vary on;
gzipcomplevel 6;
gzip_proxied any;
gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 32 8k;
gzip_disable "MSIE [1-6].(?!.*SV1)";
Can anyone help me with this? I even increased gzip_buffers slot to 32(8k) from 16(8k) since the js file was huge…
Best Regards,
Jimish
6 Replies
Request URL:
Request Method:GET
Status Code:200 OK
Response Headers
Connection:close
Content-Encoding:gzip
Content-Type:application/x-javascript
Date:Mon, 13 Dec 2010 12:07:03 GMT
Last-Modified:Sun, 12 Dec 2010 23:04:20 GMT
Server:nginx/0.8.53
Transfer-Encoding:Identity
Vary:Accept-Encoding
However it's still a 6000 line long file you should consider using a js compressor.
(or something like " --header 'accept-encoding: gzip'")
It's reporting an uncompressed size of 303,618 bytes, and a compressed size of 71,775 bytes. Considering that the gzip modules of most webservers (lighty, at least) have zero overhead on compressed static files due to caching, not a bad improvement
Google makes a javascript compiler called Closure that seems to be the most efficient "javascript compressor" available (tests show it beats out YUI and jsmin, at least). In advanced mode, where it gets aggressive with optimizations which may or may not require code changes to use, it reports:
117.56KB (36.99KB gzipped)
In simple mode, which is safer in terms of not requiring code changes, but is less efficient:
162.92KB (43.98KB gzipped)
So, with little effort on your part, Closure gets your javascript down from 70KB to 44KB. With some effort on your part, it can help you get down to 37KB.
Here's the link:
Yes, I can compress it further as you guys told and its one of the thing on my list. Thanks guspaz for the links.
1 more question: Any specific browsers that might not be able to deal with compressed files?
@jimishjoban:
1 more question: Any specific browsers that might not be able to deal with compressed files?
NCSA Mosaic? Any browser should let the server know if it can handle compressed files or not.