开发者

Capture CSS route in MVC

开发者 https://www.devze.com 2023-03-28 05:16 出处:网络
I\'m using the Asp Sprite and Image Optimization Framework located here to handle any css sprites in my site. Depending on the brower the framework generates two different links pointing to these two

I'm using the Asp Sprite and Image Optimization Framework located here to handle any css sprites in my site. Depending on the brower the framework generates two different links pointing to these two files

  /App开发者_开发技巧_Sprites/highCompat.css  - ie9, firefox, chrome

  /App_Sprites/lowCompat.css   - ie6, ie7

Unfortunately the css files are not minified and cannot be moved from their current location.

I have my own minification engine though wrapping around the Ajaxmin library where I use a handler to fling out compressed css on the fly.

This will capture a path like this.

/css.axd?path=reset.css|style.css|helpers.css

How could I with MVC capture the request and rewrite it so the css is served through my minifier?

Cheers!


Pretty easy, really: Put the CSS somewhere other than where the URI in your markup points.

IIS won't run route handlers if the physical file exists. So if your site has a physical ~/App_Sprites/highCompat.css file, your app won't be able to intercept it (though you could do this with a HttpModule). But if you put the file elsewhere and have a App_SpritesController then you can handle things as usual in MVC.

So either write an HttpModule (this would probably be my choice) or, if you must do it through MVC, relocate the file.

0

精彩评论

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