A LIST Apart: For People Who Make Websites

No. 304

Discuss: Better JavaScript Minification

Pages

 1 2 3 >

1 Google closure compiler

When comparing YUI compressor with google closure compiler, the last one can achieve better results: http://www.bloggingdeveloper.com/post/Closure-Compiler-vs-YUI-Compressor-Comparing-the-Javascript-Compression-Tools.aspx

posted at 10:40 am on April 20, 2010 by alex.objelean

2

That is partially true. The Closure Compiler can result in smaller code by manipulating the underlying code structure, but it doesn’t do safe variable name replacement. In the presence of eval(), you could end up with broken code as it doesn’t turn variable replacement off. It also performs other optimizations that may result in unintended changes to your code’s functionality. While it shows promise, I’m not ready to recommend the Closure Compiler over the YUI Compressor.

posted at 01:06 pm on April 20, 2010 by Nicholas C. Zakas

3

1. eval and with are JavaScript features you should generally avoid. This is regardless of whether you are using any minification tool. Minification is quite possibly the least of the reasons why eval and with are evil.

2. The following practices are similar to eval, and should be avoided for the same reasons: – using the Function constructor – passing strings to window.setTimeout or window.setInterval

why with is evil and why eval is evil

posted at 02:58 pm on April 20, 2010 by dsevil

4

Really nice article Nicholas. I can’t really get into the details of the usage of eval and with but i can easily say that, not only in Javascript but with any language you write your code in, optimizing the code is something any developer should do :)

posted at 03:59 pm on April 20, 2010 by Tasarım

5

I can see some issues as well with the usage of eval and with, but i still concur that you have to minify your javascript somehow. It’s just a matter of choice imho.

Nice article.

posted at 04:34 pm on April 20, 2010 by Anksiyete

6

Thanks for the comments, everyone. Just to clarify: the point of the article was not to simply say “avoid doing this,” but rather to give a clear description of why to avoid doing this (as I think everyone has heard “don’t use eval” and “don’t use with”, but rarely is there a nice description of why).

posted at 12:07 am on April 21, 2010 by Nicholas C. Zakas

7 Minifying vs. faster internet connections

Fantastic article and a great eye-opener. However, when most of the internet-using world could be on lightning fast connections within half a decade, is it still going to be such a huge deal to save a couple of kb here and there?

posted at 09:25 am on April 21, 2010 by Joss

8 Smaller Faster Stronger

Having smaller files and your website downoading faster can have SEO benefits, and this is meant to be more apparent since the Google Caffeine update, so keeping your code as lightweight as possible could be very useful in terms of ranking plus it could help with improving user experience.

However I think it is always good to try and do things in the best possible manner.

posted at 12:33 pm on April 21, 2010 by SprikeWebDesign

9

Keep in mind that lightning-fast connections are still bound by physical distance. The further the bytes have to travel, the longer it will take to get there, so if I request a byte from China it takes longer to receive than if I request that same byte from next door. Also, developing countries don’t have as much high speed internet penetration as the United States. There is still a significant portion of the world that accesses the internet over modem (or equivalent).

posted at 12:08 am on April 22, 2010 by Nicholas C. Zakas

10 I'm with dsevil

No serious coder (most of the people that would be reading this article) has used either eval or with since the stone age. Reasons:

  1. They introduce security vulnerabilities
  2. They are slow aside from compression
  1. They are difficult to debug

One more reason is hardly worth an alistapart article, IMO.

That being said, it was very well written.

posted at 12:36 am on April 22, 2010 by aaronasterling

Pages

 1 2 3 >

Got something to say?

Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.

Create a new account or sign in below if you’d like to leave a comment.

Remember me

Forgot your password?

Subscribe to this article's comments: RSS (what’s this?)