JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

Javascript Compressor

clr gif
Join the Discussion

Questions? Comments?

Related Articles

Javascript Formatter

When you write your Javascript you should lay it out all nicely with loads of spaces, indentation, and comments. This makes it easier to see what you are doing as you write it and makes it easier to amend the code during the testing process. The nice layout and comments will also make it easier for you to figure the script out when you come back to it to make changes at some future date.

Uploading the script laid out like this to the internet has two big disadvantages. Firstly the comments and fancy spacing can make the script significantly bigger than the script really needs to be making for a slower loading web page. Secondly your nicely laid out and easy to read script is also easy for someone else to copy and amend to suit their own purposes.

We can solve both problems as far as is possible by compressing all of the comments and surplus spaces out of our Javascript and uploading the compressed version to our site. This will make the script as small as is reasonable and also make it more difficult for someone else to read. It wont stop someone copying your script but they will have to have a good knowledge of Javascript to be able to figure out what it does in order to amend it, perhaps a better knowledge than they would require to write it for themselves. Of course you can keep a copy of the original version of your script on your own computer to use if you need to amend the script at a later date.

So how can we easily create a compressed version of our Javascript code. Very easily. Just paste your code into the top textarea below and then press the "Compress" button. A compressed copy of your script will be output to the lower textarea from which you can easily highlight and copy it for use on your site. The form will even tell you the original and new size of the script and the percentage saving that has been achieved by compressing the script.

In: Out: Saved %:

Note that all comments are removed from the script. You may want to add a copyright notice back in at the top of your script.

Explore JavaScript

About.com Special Features

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.