From: Adam Van Den Hoven Date: 2005-10-06T06:31:44+09:00 Subject: Re: CSS switcher in Ruby? Actually there is a way to have dynamic_css.rb without breaking browser caching! I've never actually done this but from my understanding of HTTP, it should work. The trick is to not change the URL for each style, rather change something else like a cookie (if you want it to persist between visits) or a session variable(assuming you have access to one). I'm going to assume that you have figured out some way to set the cookie and have the css load itself (keeping in mind that no everyone has javascript enabled). What you need to do is leverage the Entity tags and If-None-Match headers. Lets say you have two styles Style1 and Style2. When you get a request to dynamic_css.rb and your STYLE cookie is set to to Style1 (or nothing), send your CSS for Style1. With this response add the header ETag: "Style1" Now every subsequent request will include If-None-Match: "Style1" Lets say that our cookie changes to Style2 Now we send the header ETag: "Style2" From this point on, all requests will come with: If-None-Match: "Style1", "Style2" Now here comes the magic. All you do is instead of sending your content with a 200 - OK response, send a 304 - Not Modified response and include the ETag header of the CSS you want to be used. The only thing then is how do you handle the case when the css changes. For this you can still use the If-Modified-Since header to compare with the last modified date of the rb file On 5-Oct-05, at 12:53 PM, Tom Cloyd wrote: > Gavin, > > Thanks for your contribution to this thread. > > On Wed, 05 Oct 2005 05:11:34 -0700, Gavin Kistner > wrote: > > >>> Create dynamic_css.rb (or whatever you call it) >>> >> >> FWIW - creating dynamic content breaks browser caching. (This >> should be obvious, but I thought I'd say it anyhow.) >> > > Not everyone here is whiz. I'm out of my field here, and a distinct > amateur. I work at it really hard but you might be surprized as to > what's not obvious to me (and to some others here, I expect), so > your calling attention to this is actually quite helpful. > > Now...I'm putting your comments in a note in my file on this little > project, so I can study it in the near future, since at first read, > very little of it is obvious to me! > > Thanks again, truly. > > -- t. > > ====================================================== > Tom Cloyd, MS MA, LMHC > Private practice Psychotherapist > Bellingham, Washington, U.S.A: (360) 920-1226 > << BestMindHealth.com / tc@bestmindhealth.com >> > ====================================================== > > Using Opera's revolutionary e-mail client (program): http:// > www.opera.com/mail/ > >