If a packed Javascript saves 20kb off the download size, but takes a perfomance hit to unpack, then are there any benefits, besides obfuscating the code?
I've made this a community wiki because it may be open to some discussion.
If a packed Javascript saves 20kb off the download size, but takes a perfomance hit to unpack, then are there any benefits, besides obfuscating the code?
I've made this a community wiki because it may be open to some discussion.
Short answer yes, because the client machine's unpacking time is faster than transmission, also the internet is overloaded as is, so any contribution to making things better is appreciated by anonymous, also remember that most clients will be caching this stuff, and the larger the file the more chances it will get itself or other stuff evicted from the clients cache, especially in mobile devices
Packed javascript code generally does not take longer to execute vs regular code. Most code packers will shorten variables, function names and use a host of tricks to make the source smaller. The resulting source is fully executable! You can verify this by taking a look at it during runtime with firebug. You'll see the compressed code executing in its minimized form.
The question is, why does the packing save 20kB? You should investigate making your 'normal' javascript smaller. Is the readability of your code significantly improved by putting spaces around operators, or by using very long variable and function names? The most egregious waste of bandwidth I have seen on any web content, script or page or css, is indenting with spaces. If you must indent, use tabs, or single spaces. Nothing is more wasteful than a hundred lines in a row with 20+ spaces at the beginning.
The guys at Yahoo's YSlow recommend using both a minifier and gzip compression.
The minifier will strip out whitespace, shorten variable names etc. That way you can code with proper indentation and variable names so that other developers can understand your code.
The gzip compression is probably even more valuable.
Presumably, packed JavaScript is (slightly) more efficient for the server to send, while the unpacking expense is absorbed by the client.
If the user experience is equivalent in both cases, I'd go for the packed JS.
Anytime you can push some work to the client without incurring a negative user experience, go for it, and reap the benefits of distributed computing.