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.

5 thoughts on “Dynamic CSS and the Plan of Attack

  1. What was your eventual solution? When I do this sort of thing I would rely on the operating system caching the files as necessary and then either wrap an authentication layer on top of the CSS directory or use the web server to do the authentication. The directory wouldn’t have to be publically visible, and you could still take advantage of the caching.

  2. Actually, I haven’t gotten to the implementation yet — I got sidetracked with other plumbing concerns. The issue with publicly visible directories really depends on the shared hosting provider. Unfortunately, in my experience, Windows hosts are less likely to allow directories outside of the publicly accessible web root.

  3. I’m attending the “St. Louis Day of .NET” and the “Strange Loop 2010” conferences here in St. Louis. So I have exhausted my conference budget already 🙂

  4. I saw those. I’m a bit confused about what Strange Loop is….

    Back on topic, can’t you use access restrictions on directories to control access to certain directories, even if they are in the Web root?

Leave a Reply

Your email address will not be published. Required fields are marked *