简体   繁体   中英

Minifier that preserves conditional comments?

I tried out the online JS Minifier but it cuts out conditional comments like:

 var u = navigator.userAgent;var e=/*@cc_on!@*/false;

                           BECOMES

 var u=navigator.userAgent;var e=false;

This would affect the operation of the code, so instead of manually adding the stripped out comments manually, I'm looking for a minifier that intelligently preserves these and any such comments.

YUICompressor reportedly does the needful. Here is an excerpt from a blog:

...
But fret not, it's not as bad as you think. Unfortunately, JSMin removes conditional compilation comments, but I believe this is due to not having been updated in a while, and not up to speed with modern web development practices.

Using other tools such as YUI compressor or packer does indeed work fine with conditional compilation. ...

You can read the entire post at http://robertnyman.com/2008/05/26/conditional-compilation-in-javascript/

There's also a .NET port of YUI Compressor which allows you to:-

  • intergrate the minification/file combining into Visual Studio post-build events
  • intergrate into a TFS Build (including CI)
  • if you wish to just use the dll's in your own code (eg. on the fly minification).

because this is a port of the (original) java version YUI Compressor, which Vinnie and Crescentfresh mention above, it should give you the same results BUT all in the .NET environment -- no need for java.

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM