00 Votes

YUI Compressor: Keep Some Comments

Info by Progger99 | 2012-02-19 at 23:41

By using the YUI Compressor from Yahoo, JavaScript and CSS files can be compressed so that they use less space - unnecessary comments, blanks and white space are removed, so that the file becomes smaller and can be delivered faster when loading a website.

Reserve Important Comments

However, it is not always desired to actually delete all of the comments in the file. What is with important comments such as a copyright notice at the beginning of the file? This should finally actually remain in the file and should not be deleted.

Exclamation Mark to Keep

Luckily, there is a solution for this problem in the YUI Compressor. We simply write this in our original file:

/*! this comment is kept  */
 
function(a, b, c) {
   /* this comment will be deleted */
   return a + b + c;
}

All comments, beginning with */! will be kept, while all other comments will be deleted. After minimizing, our file will look like this:

/* this comment is kept  */
function(a,b,c){return a+b+c;}

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Rename File to its Folder Name

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.