Is there an option to NOT combine the output?

Aug 21, 2009 at 9:47 PM

I don't want to combine the compressed CSS or JS files into single files.  I want to overwrite the originals.  Is this an option?

 

Thanks in advance...

TV

Coordinator
Aug 22, 2009 at 12:16 AM

Hi TV,

thanks heaps for checking out this project :) To answer your question, YES! yes you can :)

For this example, I'll assume you're using MSBuild (in some way or form). As such, you need to have a single TARGET section, per file.

Here's some sample documentation about what an msbuild file will look like, for this msbuild task.

Now lets, change it...
NOTE: please take not that the JavaScriptFiles and JavaScriptOutputFile are identical. If you need to add in some path information, both properties need to be the same.

<Target Name="MyJSFile_1">
        <CompressorTask
            JavaScriptFiles="jquery-1.3.2.js"
            ObfuscateJavaScript="True"
            PreserveAllSemicolons="False"
            DisableOptimizations="Nope"
            EncodingType="Default"
            DeleteJavaScriptFiles="false"
            LineBreakPosition="-1"
            JavaScriptOutputFile="jquery-1.3.2.js"
            LoggingType="ALittleBit"
            ThreadCulture="en-au"
            IsEvalIgnored="false"
            />
    </Target>
    <Target Name="MyJSFile_2">
        <CompressorTask
            JavaScriptFiles="MyJavaScriptFile.js"
            ObfuscateJavaScript="True"
            PreserveAllSemicolons="False"
            DisableOptimizations="Nope"
            EncodingType="Default"
            DeleteJavaScriptFiles="false"
            LineBreakPosition="-1"
            JavaScriptOutputFile="MyJavaScriptFile.js"
            LoggingType="ALittleBit"
            ThreadCulture="en-au"
            IsEvalIgnored="false"
            />
    </Target>

this is untested code, but it should be right (or near enough). Please give that a go and report back with any success/failure, please :)
I have tested this concept out, in the early days of my migration, and that worked. So this should still work.

-PK-

Aug 24, 2009 at 1:22 PM

Hey PK,

Thanks for the quick example - very much appreciated, however I'm probably not going to use this in it's current state then.  Reason being is that the websites I'm building with my TFS team build consist of over 20 css files and around 50 js files.  I'd prefer to find a solution like JSCompress from the MSBuildCommunityTasks project that can use a wild card for a directory and just writes the compressed file into the same location with the same name.  I was hoping to use your YUI.net implementation since it does CSS as well though.  If I get a chance I might dig into your source code

 

 

  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>


  <Target Name="CompressJavascript">
    <ItemGroup>
      <JSFilesToCompress Include="$(DropLocation)\WWWSite\js\*.js" />
      <JSFilesToCompress Include="$(DropLocation)\WWWSite\js\corp\*.js" />
    </ItemGroup>

    <JSCompress Files="@(JSFilesToCompress)" />

  </Target>

 

Coordinator
Aug 25, 2009 at 12:57 AM

50 JS files.. shees.. and u don't want to combine any of that??? crazy.......

20 css sorta sounds about right ... but still, combining will help _big time_. even if u combine a few of these files (where their data isn't being used on a single page) is still more performant because there's less request/response packets AND the items can (and should) be cached.

that said, I might see if I can slip in some time and try and make it, so that if u do not provide a value for the output file.. then it overwrites. I'm starting to get sick and tired of people thinking it's too much trouble to write a seperate target name for each one (which makes lots of sense if u're going to have to do it for 50 individual files).

Maybe i'm more confused to why people are having so many files and not combining so many of them..... but each to their own :)


Anyways, it's not that hard to tweak the current code to get what u want so gimme a bit of time and i'll see if i can slip this in.

HTH :)

Aug 26, 2009 at 4:25 PM
Edited Aug 27, 2009 at 10:07 AM

Hi all,

Recently I have faced with the same task. I don't want YUI Compressor to combine my files, cos I want to combine them using ScriptManager.CompositeScript. Fot this I have two reasons:

  1. It is easier for me to control which scripts I should include in combined one and which should not.
  2. It is easier to manipulate with script order (some times one script must be included before other one) for a particular page.

And in general there can be a bunch of other scenarios. It is good to add to such a powerful utility  yet another feature, isn't it? =)

And finally I have done this task. I have added a little code to perform this. All you need now is to specify two additional properties (the last ones), like this:

 

    <CompressorTask
CssFiles="@(CssFiles)"
DeleteCssFiles="false"
CssOutputFile="$(CssOutputFile)"
CssCompressionType="YuiStockCompression"
JavaScriptFiles="@(JavaScriptFiles)"
ObfuscateJavaScript="true"
PreserveAllSemicolons="False"
DisableOptimizations="Nope"
EncodingType="Default"
DeleteJavaScriptFiles="false"
LineBreakPosition="-1"
JavaScriptOutputFile="$(JavaScriptOutputFile)"
LoggingType="ALittleBit"
ThreadCulture="en-us"
IsEvalIgnored="false"
SaveJsInSeparateFiles="true"
SeparateJsFileSuffix=".min"
/>

"SaveJsInSeparateFiles" - doesn't require explanation.

"SeparateJsFileSuffix" - suffix that will be added to the resulting file name,  e.g.  if you have file named "MyScript.js" after compression you will see another one with name "MyScript.min.js". If you want files to be replaced specify an empty string or nothing.

 

P.S. Now I am trying to connect to SVN to check-in my changes.

 

Aug 27, 2009 at 10:06 AM

I have just uploaded a patch with my changes. I have insufficient rights for commiting changes into SVN.

Sep 28, 2009 at 11:13 PM

Actually if you just want to just create a minified version of each file, you can use MSBuild Batching:

    <CompressorTask
CssFiles="@(CssFiles)"
DeleteCssFiles="false"
CssOutputFile="$(CssOutputFile)"
CssCompressionType="YuiStockCompression"
JavaScriptFiles="%(JavaScriptFiles.Identity)"
ObfuscateJavaScript="true"
PreserveAllSemicolons="False"
DisableOptimizations="Nope"
EncodingType="Default"
DeleteJavaScriptFiles="false"
LineBreakPosition="-1"
JavaScriptOutputFile="%(JavaScriptFiles.Identity).min"
LoggingType="ALittleBit"
ThreadCulture="en-us"
IsEvalIgnored="false"
/>
You could then have another process that renames the new .js.min files to .min.js
Sep 29, 2009 at 12:27 AM

This may even be a bit easier. Assuming your source js files end with ".debug.js" the following MSBuild tasks create files ending in ".debugMinified" and then renames these files to ".min.js".

<ItemGroup>
  <CssFiles Include="*.css" />
  <JavaScriptFiles Include="**\*debug.js" />
</ItemGroup>
<CompressorTask
    CssFiles="@(CssFiles)"
    DeleteCssFiles="false"
    CssOutputFile="$(CssOutputFile)"
    CssCompressionType="YuiStockCompression"
    JavaScriptFiles="%(JavaScriptFiles.Identity)"
    ObfuscateJavaScript="True"
    PreserveAllSemicolons="False"
    DisableOptimizations="Nope"
    EncodingType="Default"
    DeleteJavaScriptFiles="false"
    LineBreakPosition="-1"
    JavaScriptOutputFile="%(JavaScriptFiles.RecursiveDir)%(JavaScriptFiles.Filename)Minified"
    LoggingType="ALittleBit"
    ThreadCulture="en-au"
    IsEvalIgnored="false"
        />
<ItemGroup>
  <MinifiedJavsScriptFiles Include="**\*.debugMinified" />
</ItemGroup>

<Exec Command="move %(MinifiedJavsScriptFiles.Identity) %(MinifiedJavsScriptFiles.RecursiveDir)%(MinifiedJavsScriptFiles.Filename).min.js" />

 

Oct 6, 2009 at 10:41 AM

Hi, fcheung

Thank you for your reply. Is is also a very good solution. This is the case when not a very strong knowledge of MS Build brings another useful feature to this library =)

Jan 29, 2010 at 9:32 AM
Edited Jan 29, 2010 at 9:34 AM

Here's how I did it. You need MSBuild 3.5 in order to use "Remove" inside the <ItemGroup>.


<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
  <UsingTask TaskName="CompressorTask" AssemblyFile="Yahoo.Yui.Compressor.dll" />

  <Target Name="MyTaskTarget">
     <ItemGroup>
      <JavaScriptFiles Remove="@(JavaScriptFiles)" />
      <JavaScriptFiles Include="../js/1.js" />
    </ItemGroup>
    <CompressorTask
      JavaScriptFiles="@(JavaScriptFiles)"
      ObfuscateJavaScript="True"
      PreserveAllSemicolons="False"
      DisableOptimizations="Nope"
      EncodingType="Default"
      DeleteJavaScriptFiles="false"
      LineBreakPosition="-1"
      JavaScriptOutputFile="../js/1.min.js"
      LoggingType="ALittleBit"
      ThreadCulture="en-au"
      IsEvalIgnored="false"/>

    <ItemGroup>
      <JavaScriptFiles Remove="@(JavaScriptFiles)" />
      <JavaScriptFiles Include="../js/2.js"/>
    </ItemGroup>
    <CompressorTask
      JavaScriptFiles="@(JavaScriptFiles)"
      ObfuscateJavaScript="True"
      PreserveAllSemicolons="False"
      DisableOptimizations="Nope"
      EncodingType="Default"
      DeleteJavaScriptFiles="false"
      LineBreakPosition="-1"
      JavaScriptOutputFile="../js/2.min.js"
      LoggingType="ALittleBit"
      ThreadCulture="en-au"
      IsEvalIgnored="false"/>
 
    <ItemGroup>
      <JavaScriptFiles Remove="@(JavaScriptFiles)" />
      <JavaScriptFiles Include="../js/3.js" />
      <JavaScriptFiles Include="../js/4.js" />
    </ItemGroup>
    <CompressorTask
      CssFiles="@(CssFiles)"
      DeleteCssFiles="false"
      CssOutputFile="../css/release.css"
      CssCompressionType="YuiStockCompression"
      JavaScriptFiles="@(JavaScriptFiles)"
      ObfuscateJavaScript="True"
      PreserveAllSemicolons="False"
      DisableOptimizations="Nope"
      EncodingType="Default"
      DeleteJavaScriptFiles="false"
      LineBreakPosition="-1"
      JavaScriptOutputFile="../js/3.min.js"
      LoggingType="ALittleBit"
      ThreadCulture="en-au"
      IsEvalIgnored="false"/>
</Target> </Project>

 

 

 

Mar 23, 2010 at 5:59 PM

PK -

I am trying to use these 2 attributes but it doesnt work. Is this not available in dotNet 2.0 version or have I downloaded the wrong version (http://yuicompressor.codeplex.com/releases/view/36891#DownloadId=95836)?

"SaveJsInSeparateFiles="true" and SeparateJsFileSuffix=".min"

Any advice?

Mar 25, 2010 at 10:11 PM

Hi,

This is because my patch wasn't applied yet. You can get it separately here. Hope it helps.