0

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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

The problem with moving the file is that the path is generated dynamically based upon the observing browser. highCompat for ie9, firefox etc and lowCompat for ie6, ie7. I've updated my question to clarify that.
That's not a problem at all. The folder always seems to be the same. So just override HandleUnknownAction. The actionName argument will be the filename.
Ah... I think I'm starting to see the light. A quick Google seems to suggest I should tread carefully in how I implement this. Do you have any code samples?
Ignore the above... I used a HttpModule. 6pm on a Friday... My brain is fried!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.