开发者

Compress Individual Files using YUI Compressor .Net

How can i compress individual css files using YUI build task (or otherwise). Scenario: I have

  • Style.css,
  • IFrame.css,
  • Grid.css

I can compress 开发者_运维技巧and merge these files to main.min.css (no problem here, got a sample from yui on codeplex).

However, I also have a Contact.css that is only used on the contact page. How do I compress this file seperately from the others? i.e into contact.min.css


Might look into RequestReduce. We are also creating a bundling/minification for ASP.NET (MVC, Web Pages, Web Forms). See http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx


If I understand your issue right, you can create multiple bundles.Here I'm using YUI Compressor.Net , but it can be standard bundle from System.Web.Optimization namespace.

        var cssBundleConfig = new CssCompressorConfig();
        var cssTransform = new YuiCompressorTransform(cssBundleConfig);

        bundles.Add(new Bundle("~/Content/basecss", cssTransform).Include(
                  "~/Content/Css/Style.css",
                  "~/Content/Css/IFrame.css",
                  "~/Content/Css/Grid.css"
                  ));
        bundles.Add(new Bundle("~/Content/contactcss", cssTransform).Include("~/Content/Css/Contact.css"));

And call render on UI like:

@Styles.Render("~/Content/basecss")
@Styles.Render("~/Content/contactcss")

But this is runtime process, not build phase task. May be there is similair solution for build.


Have you tried using the following plug-in http://chirpy.codeplex.com/. It allows you to compress all your css and javascript at build time automatically. I've used it in a few projects and seems to work well.


I am now using Cassette. The next VS will have this built in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜