Problems with javascript minification that affects SwfObject 2.1 in Internet Explorer

This is actually a more general issue with javascript minification that can affect a number of scripts, but I noticed it while tracking down weird behaviour with the minified version of SwfObject that only affected Internet Explorer.

Basically, standard behaviour with most javascript minifiers is to strip out anything contained within comments. I finally tracked down this piece of code in the swfobject library that was getting stripped out (incorrectly) by the minifier…

/*@cc_on
ie = true;
@if (@_win32)
windows = true;
@elif (@_mac)
        mac = true;
    @end
@*/

This library carries out browser detection by using the proprietary Conditional Compilation feature in Internet Explorer. In order to stop other browsers from choking, the code is wrapped in a comment.

I’m not commenting whether this is a good or bad idea, simply that it does appear in existing scripts, and causes a bunch of javascript minifiers to strip out functional code.

I think my approach will be to revise the set of regular expressions that control what gets stripped out to cater for this variation.

Posted:

March 26, 2009 @ 12:01

Categories:

Development

Tags:

, ,

Comments:

No comments so far

Comments RSS feed for comments on this post.

No comments yet.

Leave a comment