YUI Compressor and .NET Apps
.net, build, optimization, process
Solution
I use both. The YUI compressor is command-line, and easy to integrate into any build process. I got it running in rake with no problems.
It's probably most common to perform the javascript/css compression in-place when you deploy. That way you don't have to update JS references. But I'm using another method on my site. I have the compressed files created as `*-min.js`, etc. To include a script or css file on my page, I call a server-side method:
<%= ScriptSrc("~/assets/myscript.js") %>
<%= LinkSrc("~/assets/main.css") %>
These methods do the following:
- Expand the app-relative path
- add a version string to the end (for cache invalidation)
- choose between the full script and a minified version depending on whether we are in debug mode or not.
In debug mode, `ScriptSrc` might output something like this:
<script type="text/javascript" src="http://stage.myapp.com/assets/myscript.js?v=1.2" ></script>
but in production it would load the minified version:
<script type="text/javascript" src="http://stage.myapp.com/assets/myscript-min.js?v=1.2" ></script>
One of the benefits of this is that I can switch between the full and minified versions just by changing the `web.config`, which can aid debugging.
Problem
I want to use YUI Compressor (the original) and use it as part of typical MS build processes (Visual Studio 2008, MSBuild). Does anyone have any guidance or thoughts on this? For example, good ways for incorporating into project, what to do with existing CSS and JS references, and the like. I am happy to hear on the benefits of YUI Compressor .NET and alternatives but I'm more interested in use of the original. Thanks Scott