Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript comment starting with /*!

My editor (Geany) changes the colour of a comment when a comment starts with /*!. What's the difference between /* ... */ and /*! ... */?

like image 409
Phonethics Avatar asked Jun 10 '10 07:06

Phonethics


Video Answer


2 Answers

The ! prevents YUI compressor from removing the comment when it compresses. (It just removes 1 ! instead. Multiple !'s mean you can compress multiple times without loss of the comment.) It's just an extension, but not part of javascript itself.

Documentation is here. Search for 'C-style comments'.

also, I'm not aware of any other compressors that respect the !. Packer, closure compiler, shrinksafe, and jsmin do not respect it at least.

like image 80
x1a4 Avatar answered Oct 12 '22 05:10

x1a4


They are both treated as comments in JavaScript. For the second one, since the exclamation is inside, JavaScript doesn't care what's inside the comment anyway.

Tools that minimizes or compresses JavaScript files would get rid of anything inside /* ... */, but would leave the second style of comment intact. The reason is so that there's a way to keep the copyright information in the minified or compressed version of JavaScript files.

like image 22
Kevin Le - Khnle Avatar answered Oct 12 '22 05:10

Kevin Le - Khnle