Dynamic CSS and the Plan of Attack

I’m working on an ASP.NET website where I need to generate dynamic CSS, mostly for “theming” purposes. I really don’t like .NET skins or themes – I prefer straight CSS and markup; besides, it needs to be configurable through an administration page and persisted to a database. Here are the options I’m contemplating:

  1. Allow the client to define CSS styles and generate a flat file based on what is in the database when the web application loads (if no file exists, write one – reference that for every subsequent request). The downside is that I have to write to the filesystem, which means at least one publicly exposed directory must be writeable by some process. The upside is that browsers will cache the file, so no subsequent requests are needed.
  2. Allow the client to define CSS styles and write them to the output stream using a specialized instance of IHttpHandler. The upside is that, well, this appeals to the code monkey in me. The downside is that I’m not sure if a browser will cache this since it’s not a CSS file per se. I suppose some experimentation is in order.

If anyone has experience with this, please let me know what solution you settled on.