Used YUI Compressor but problems in minified js

Nov 30, 2011 at 6:14 PM
Edited Nov 30, 2011 at 6:15 PM

Hi,

I have used YUI Compressor for .Net.

But when I run my web project; my browser gives a lot of js errors.

For example consider following js Code:

var obj = {

 name: 'ABC',

        //Some comment line

       age: function() {

       }

}

 

minified js file code looks something like of following:

var obj={name: 'ABC', //Some comment line age: function() {

}}

You see comments are mingling wrong way. Such incorrect minified code certainly would not work at all.

Can anyone tell, what should I do ?

I can paste the code tomorrow if someone wants to have a peek over it.

Thanks

Coordinator
Jan 27, 2012 at 8:07 AM
Edited Jan 27, 2012 at 8:15 AM

What parameters are you supplying to YUICompressor?

This test passes for me:

    [TestMethod]
    public void TopGun743()
    {
        var source =
            @"var obj = {
                     name: 'ABC',
                    //Some comment line
                   age: function() {
                    }
                }";
        var actual = JavaScriptCompressor.Compress(source);
        Assert.AreEqual(@"var obj={name:""ABC"",age:function(){}};", actual);
    }
Coordinator
Jan 27, 2012 at 11:33 AM

@TopGun743 also, are you using the dll's via NuGet? Manual download? which dll version also? .NET 2.0 version or the .NET 3.5 version?

Jan 29, 2012 at 10:20 AM

Sorry for replying late     (though the coordinators also replied me much late :)    )

Anyways, the problem that I mentioned in the post, I did in Nov, was resolved by myself. Actually I was trying to apply the css compression related code to a js file, means somewhere in my code against compression type I was mentioning css when it should've been js compression type. Guess it was some typo or copy/paste issue :)

It works fine with just one more question:

How do I compress .JSP files that include HTML, css, javascript and server side java sciptlets (in the form of

<%

//java code lines..............

%>

etc  ?

I have tried to apply js compression on JSP files but it would not work out.

Is it possible with some work around/trick ?

Thanks for devoting your time

Coordinator
Jan 29, 2012 at 10:31 AM
Hi,

Glad your issue is sorted out.

YUICompressor is designed to compresss CSS and JavaScript files only.

It is not intended to compress HTML or indeed any server side code.

It is usually a good idea to separate your CSS and JavaScript from your server markup and server side code, so I would put them in separate include files, which you can use YUICompressor then to compress as part of your build.



On 29 Jan 2012, at 10:20, topgun743 <notifications@codeplex.com> wrote:

From: topgun743

Sorry for replying late (though the coordinators also replied me much late :) )

Anyways, the problem that I mentioned in the post, I did in Nov, was resolved by myself. Actually I was trying to apply the css compression related code to a js file, means somewhere in my code against compression type I was mentioning css when it should've been js compression type. Guess it was some typo or copy/paste issue :)

It works fine with just one more question:

How do I compress .JSP files that include HTML, css, javascript and server side java sciptlets (in the form of

<%

//java code lines..............

%>

etc ?

I have tried to apply js compression on JSP files but it would not work out.

Is it possible with some work around/trick ?

Thanks for devoting your time

Mar 11, 2012 at 6:51 AM

I have an issue with YUI Java script file compression. We have an Ant task to build the project from SVN repository. Whenever a JS file is modified in SVN and build is run, that file is not compressed properly. Compressed file is appended  with the original non compressed file...Any idea??

 

Thanks in advance!!!

Coordinator
Mar 11, 2012 at 12:12 PM

Hi,

Are you sure you are in the right place?  If you are using ANT then perhaps you are using the original Java YUI compressor, not our port, so the most appropriate place to ask questions about that is in their forums?  This is the home of the .NET port of YUI Compressor, so I would expect you to be talking in terms of MSBuild or NANT tasks...

Regardless, you would definitely need to provide more information - the build script fragment for calling the compressor would be a good start, preferably an entire isolated example of the problem you are having.  Without seeing what you are doing, we, or the Java guys can only guess at what's going on....