Avoid minification with IE conditional javascript

[tweetmeme]
In order to save bandwidth, merging and minification of CSS and JS; assets is really useful.  However be wary of including any code in that which uses IE conditional javascript.  Something I did not realise existed until digging into this issue, despite many years of conditionally dealing with different browsers!  For those not in the know, in IE /*@cc_on!@*/ will “evaluate” to ! thereby making var isIE = !false; which is true, of course.  Any other browsers will ignore the comment and set var isIE = false.

Helpful until that code is run through a minification which strips all comments and is not aware of such things!

Annoyingly, code from a 3rd party that is part of our application was being minified in production mode and uses this technique to identity if a browser is IE or not.  Which gave very spurious results when testing IE…  The solution for us, rather than hacking the 3rd party code was to use a direct include of the file into the pages that require it, and to use ?v=x.x.x after the filename in the source to ensure we can still force reloads in clients after we make changes to it (probably just an upgrade) in future.  This was something the merging and minification process kindly gave us for free.  In this case I made the number match the version of the 3rd party source we are using for consistency.  This is a pain in that it requires changes to templates and it not automatic, but modifications to the included file in this case are likely to be rare, and is the easiest option allowing the rest of our assets to still be merged and minified.