[TIP] Google Closure for JS


New member
This is a very helpful tip for those who want to cut in bandwidth usage.

Google has a service in which you can upload JS files and they will pack it, removing comments, useless blank space, etc and will shorten your scripts (like replacing false with !1 and undefined with void 0).
I actually use it in one of my works as the default packer for JavaScript with a simple cache system I created to avoid packing every time some user requests the file.
This way you can save lots of bytes in bandwitdh removing areas of the code who only interest the programmer and you obfuscate your javascript for harder copy.
I also use the Dean Edwards packer in php and gzip for the best compression.

  • Use SIMPLE_OPTIMIZATIONS. ADVANCED_OPTIMIZATIONS is only for when you want to pack ALL the scripts used in the page
  • I prefer curl for requesting the pack (it's faster), but they also offer a java version for command line packing, use the one who suits your needs (and your hardware)
  • Use it with a cache, the compression can take time and it's bad for page loading time