We are going to write a JavaScript compressor tool as well as a decompressing tool. Consider the following JavaScript:
$ cat sample.js
function sign_out()
{
$("#loading").show();
$.get("log_in",{logout:"True"},
function(){
window.location="";
});
}
Our script needs to perform these steps to compress the JavaScript:
- Remove newline and tab characters.
- Remove duplicated spaces.
- Replace comments that look like /* content */.
To decompress or to make the JavaScript more readable, we can use the following tasks:
- Replace ; with ;\n
- Replace { with {\n, and } with \n}