PDA

View Full Version : Pack JS Files ?



Cheng
04-17-2009, 02:03 PM
Hi.

Is there a way or a tool to pack js files in order to speed up loading times?

I know that it is possible but I'm looking for an easy way to achive it.

Please give me some advise,

Snookerman
04-17-2009, 02:30 PM
You mean like a minifier? This is a good one: http://fmarcia.info/jsmin/test.html (http://fmarcia.info/jsmin/test.html)

Good luck!

Cheng
04-17-2009, 04:51 PM
.......thanks a lot, this is what I was looking for.

I found one myself as well by now which is quiet nice:

http://dean.edwards.name/packer/

Does the packing really speed up the loading process or does it just compress the file size...?...

Master_script_maker
04-17-2009, 05:40 PM
Those two things go hand-in-hand. The smaller the file size, the faster it will load.

Twey
04-17-2009, 06:21 PM
That's not necessarily true. A lot of packers use eval(), which will actually considerably slow the loading process overall, since it's still loading the full-sized script, but with an extra compiler instance started up first, plus the overhead of unpacking.

Master_script_maker
04-17-2009, 06:47 PM
Yes you are right about that. On a small script (~1000 characters) it took four times longer packed, then unpacked. But the code does get to the browser faster and is smaller, therefore compromise is needed. In my opinion most scripts should only have whitespace stripped and variables shrunk.

Cheng
04-18-2009, 01:37 AM
.......what I'm using is a large js file which is 48 kb and packed it is only 22 kb.

Since I'm on a dialup connection at the moment using my mobile to connect I'm very concerned about speed and I noticed that with the packed js file the site is defnitely loading faster.......

Twey
04-19-2009, 12:30 AM
There's loading speed, and there's transfer speed. A basic packer, just renaming identifiers and stripping whitespace and comments, can increase transfer speed (by making the file smaller) and also marginally increase loading speed (since there's less to parse). However, eval()-based packers will increase transfer speed possibly a little more (if written with care), but at the cost of vastly reducing loading speed. Both options, of course, leave the final script pretty much unreadable.

There is a better solution: all modern browsers and servers support on-the-fly gzip compression. Using this will significantly decrease the amount of network traffic, at the cost of a little more resource usage on either end. Best of all, it's transparent: you can just enable it and forget about it. Everything will happen automatically, and your users will see a fully-featured, unobfuscated, readable script.

Cheng
04-19-2009, 07:44 AM
.......for the beginning I'm using a packer like mentioned above because I couldn't figure out as yet how to use the on-the-fly gzip compression and the packers are easy to use.......