Sunday, August 31, 2008 2:22 PM
The other day we were restructuring some CSS files in a project I am working on. And we were thinking of the best way to specify one CSS file differently for each end user account in the project since each end user has the ability to control some aspects of the way the site looks when he/she logs in. Specifically each end user can control two main colors in the site's design. After some thoughts we ended up feeling we wanted somehow server side CSS in which we can write our CSS but instead of hardcoding two colors in the file, we want them as variables that we can inject from the server side from some code behind.
To use this file, instead of specifying your CSS file like this:
<link rel="stylesheet" type="text/css" href="sample.css" />
You specify your CSS like this now:
<link rel="stylesheet" type="text/css" href="sss.aspx?sample.css" />
The script also supports returning the result as GZIP or DEFLATE compressed, if the client browser supports it. And finally it provides proper cashing handling and proper Last-Modified headers handling. Once the file combined is served to the client, it will not be served again as long as you do not modify the source CSS or JS files. I have written the C# code inline to make it very easy to add to your own projects, just add the sss.aspx file.
Here is a recap of the benefits:
- Combine several script files into one file to speed things up.
- The returned stream will be compressed if the client browser supports it.
- Automatically add common script files that you need in all your site without having to specify them each time.
- Proper cashe handling and proper Last-Modified headers handling.
- Add your script file types easily.