views:

549

answers:

5

I have a number of files which I combine and pack to produce a single, minified JS file. The problem is that when I minify the file (using packer), IE6 gives one of its characteristic helpful error messages.

Line: 12      // of course, line 12 is an empty line
Char: 1
Error: Expected ')'
Code: 0

The thing is: it works fine in IE7, Firefox and Chrome the problem only comes up for IE6.

Unpacked, I have almost 200kb of scripts spread through 8 files. How on earth do I fix this?

+1  A: 

Like CMS said, the YUI compressor is a great tool to compress and obfuscate your code, try that.

I use the following code on my javascript files. I'm running on OSX, but the command should be identical on Linux and possibly also on Windows (though I never tried).

java -jar /path/to/yuicompressor-2.4.jar --charset utf8 -o ~/path/to/scriptname.min.js ~/path/to/scriptname.js

Where ~/path/to/ is the path to wherever your javascript file is, scriptname.min.js is the name of the minimized/obfuscated end result, and scriptname.js is the original file.

I'm assuming you cannot just 'forget' about IE6? One of my new year wishes is that the last 23% of IE6 users on the internet finally upgrade to a more decent/up-to-date browser :-).

Hope this helps!

-Dave

Dave
+1  A: 

this is a very common problem with ie6, you have to pay attention to the closures in your code,

the condition statements must be with { - } ... and function too.

if(){
}

function(){
};

you must put ; on the end of each statement , if not , the lines will merge into something that the browser cannot understand.

i use jslint.com for javascript debugging. look for the "missing semicolon" in the error list.

Moran
+1  A: 

Have you already verified that the un-minified code can run successfully in IE6? If so, because this is a syntax error and not a runtime error, the next step I'd take is start halving the javascript, minifying it, and seeing when the problem stops being reported. Then continue binary searching from there.

Browsera
A: 

From memory, I think the way I solved this problem in the end, and the way I generally tackle problems with minified code now, is to run it through JSLint. Its extraordinary strictness will pick up problems (eg missing semicolons) that don't cause problems on non-minified code. You'll have to trudge through a lot of not-really-an-error messages, but the problem will be in there somewhere!

nickf