Compressing Javascript files.

Hello,

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://desidime.com/javascripts/beast.js

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

It is working, probably something to do with curl, maybe it doesn't accept gzip encoded data, here's my output from safari

Request URL:http://desidime.com/javascripts/beast.js

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.

try the "–compressed" option for curl

(or something like " --header 'accept-encoding: gzip'")

PipeBoost, who sell compression software for IIS, has a nice "compression checker" tool:

http://www.pipeboost.com/GetReport.asp? … s/beast.js">http://www.pipeboost.com/GetReport.asp?URL=http://desidime.com/javascripts/beast.js

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: http://code.google.com/closure/

thank you guys very much. Yes, I confirmed its compressing correctly.

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.

I've heard IE6 gets confused by compressed JavaScript, which is presumably why you have that "gzip_disable" line in your config. Any remotely decent client will either handle compression right or not ask for it in the first place.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct