I've noticed that initial comment in JavaScript or CSS files is sometimes started with /*!
.
What is the purpose of the explanation mark?
For example, jQuery:
/*! jQuery v1.7.1 jquery.com | jquery.org/license */
/*!
* Bootstrap v2.0.1
*
* Copyright 2012 Twitter, Inc
4 Answers 4
It tells compression tools such as the YUICompressor and Uglify, which minify the code, to leave the commented section in place as they usually remove all comments from the code.
-
Is there a way to override this without removing the !? I'm using Uglify and I need to remove all blocks so I can inject the CSS file into my HTML.Kevin– Kevin2013年08月22日 14:20:51 +00:00Commented Aug 22, 2013 at 14:20
-
5Of course, the point of leaving these comments in, usually, is because they are licensing messages that are required to be included with any distributed versions of the code.Asfand Qazi– Asfand Qazi2013年09月19日 11:20:04 +00:00Commented Sep 19, 2013 at 11:20
-
5Licenses are meant to be always present with code so you may violate some rights by removing them.keaukraine– keaukraine2013年09月20日 08:20:22 +00:00Commented Sep 20, 2013 at 8:20
-
Now deprecated?Peter Mortensen– Peter Mortensen2023年09月12日 14:37:51 +00:00Commented Sep 12, 2023 at 14:37
Some software like Coda also support the "bookmark syntax" shown below, so that one can navigate to different parts of code through the app's code navigator.
// !bookmark
/* !bookmark */
<!-- !bookmark -->
Note that in the examples above there's a space between the comment syntax the exclamation mark.
I believe one purpose of the exclamation point is to tell JavaScript minifiers to leave these particular comments in, when condensing the files.
It is also important for attribution for the author of external dependencies/API, especially free ones.
When minifying, the least we can do is to offer them some bytes of recognition.
e.g. /*! PhotoSwipe main CSS by Dmitry Semenov | photoswipe.com | MIT license */
will not be erased by minifier.