51

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:

/*!
 * Bootstrap v2.0.1
 *
 * Copyright 2012 Twitter, Inc
0

4 Answers 4

66

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
Of 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.
Licenses are meant to be always present with code so you may violate some rights by removing them.
Now deprecated?
4

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.

Comments

4

I believe one purpose of the exclamation point is to tell JavaScript minifiers to leave these particular comments in, when condensing the files.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.