Thursday, August 04, 2011

Compressing or Decompressing of Javscript Code

If the javscript code is huge in size, it will affect the loading time of your website. So you can compress the javscript code inorder to
  • transmit JavaScript faster,
  • Reduce the number of HTTP requests etc.

How to Compress Javascript code ?

Use Packer.

Go to http://dean.edwards.name/packer/ . Paste your code in the text area there and "Pack" it. You will get the compressed code. Use that compressed code instead of your original script in your website. You can also encode (base 62 encoding) while compressing.

How to Decompress the Javascript code compressed by /packer/

The /packer/ compressed code looks like eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseint(c/a))).... . To decode it , Replace "eval" by "alert".