开发者

Deploying images after CSS Minification/Merging

I'm using Visual Studio 2010, .NET 4 and MVC 2 on this project with YUI Compressor running as a post build event.

The thing is we had one big css file which was not maintainable so we've split it into many CSS files in different folders.

  1. /Assets/Styles/Site.css
  2. /Assets/Styles/Pages/Page1.css
  3. /Assets/Styles/Pages/Page2.css
  4. /Assets/Styles/Pages/Page-nth.css
  5. /Assets/Styles/Partials/Partial1.css
  6. /Assets/Styles/Partials/Partial1.css
  7. /Assets/Styles/Partials/Partial-nth.css

Something like that.

This is good for development but not for p开发者_如何学JAVAroduction. On production we only have 1 file, which is a merged/minified version of everything, this file sits at /Assets/Styles/style.css

Now this design is causing problem because the image paths can't be the same in dev and prod. (we also have staging and uat but lets keep things simple)

I see a few solutions to that, we could use absolute paths, we could have many minified/merge css files and put them in the right folder (Pages.css / Partials.css) or we could use a cookie-free subdomain (static.domain.com) which is what I would like to do.

So my question is: How do I automatically rename "../../image.png" to "http://static.domain.com/image.png" in my CSS files automatically?? Can YUI Compressor do that? Should I make a build console projects that does just that? Do you know a tool that will do that for me? Other suggestions?!

Thanks in advance!


YUI-compressor can not do that.

You need to loop over the files and replace every path with the new absolut path. You can easily do this with a regex. I don't know if you can do this easily in windows-batch but it's easy with unix sed or any script (perl, python...). If you are more familiar with .NET you can build a console project and run it as a post build event.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜