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
Peter Mortensen
31.6k22 gold badges110 silver badges134 bronze badges
asked Jun 28, 2012 at 15:53
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.

Ollie Bennett
4,5041 gold badge21 silver badges26 bronze badges
answered Jun 28, 2012 at 15:56
4
  • 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. Commented Aug 22, 2013 at 14:20
  • 5
    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. Commented Sep 19, 2013 at 11:20
  • 5
    Licenses are meant to be always present with code so you may violate some rights by removing them. Commented Sep 20, 2013 at 8:20
  • Now deprecated? Commented Sep 12, 2023 at 14:37
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.

answered Sep 20, 2013 at 8:15
4

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

Peter Mortensen
31.6k22 gold badges110 silver badges134 bronze badges
answered Jun 28, 2012 at 15:57
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.

answered Aug 31, 2017 at 19:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.