Syntax error using Yahoo YUI Compressor .net port – works using java version

Recently, I was tasked with creating a minified version of a web applications Javascript files.

I settled on the Yahoo YUI Compressor, in particular, the .net port of it

When I tried to compress a particular file (the jquery.caret plugin), it would throw up a syntax error.

This error only occurred using the .net port of Yahoo YUI Compressor.
Using the standard java jar version of YUI Compressor did not throw such an error.

The error was a syntax error on this line:

(function($,len,createRange,duplicate){

It was saying invalid character at position 0.

After some time scratching my head, I opened the file in notepad++ and converted text to hex 16
Immediatlely, I could see there were some invalid characters around the function text:

Hex characters in jquery.caret

Removing those characters and saving the file solved my problem, and allowed the file to compress.

I looked at the issues page for the jquery.caret project, and found this issue had already been reported

Update

I’ve created an issue on the codeplex page for this now:
http://yuicompressor.codeplex.com/workitem/10742

Leave a Reply

Your email address will not be published. Required fields are marked *