Javascript comment stripper

Here's some code I whipped up: Check it out: here

Also here is an example of my code you can test RIGHT NOW in a webpage

Here's one I didn't write that could be handy, though his code will fail on certain regex literals: http://james.padolsey.com/javascript/removing-comments-in-javascript/

EDIT: The code I wrote is as is. I am not updating it as it is something I wrote when I was a teenager and rather new to programming. If there is a bug, you can fix it.


Use Google's Closure Compiler with WHITE_SPACE_ONLY and PRETTY_PRINT -- the only thing that it will do is remove the comments (Unless of course you don't format your code in the way that PRETTY_PRINT does.)

It turns this:

// This function alerts a name
function hello(name) {
    /**
    * One lone
    * multi-line
    * comment
    */
    alert('Hello, ' + name);
}
hello('New user');

Into this:

function hello(name) {
  alert("Hello, " + name)
}
hello("New user");