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 <gavin@xxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxx >>
======================================================

Using Opera's revolutionary e-mail client (program): http:// www.opera.com/mail/





.



Relevant Pages

  • Re: CSS, CSS & let me give you some more CSS
    ... > Basically the general agreement is that cookie stealing via embedded code is ... > the most dangerous use for CSS and the most common. ... Their inherent security is similar too uid/pw: ... > cookie based authentication (Prime example older versions of Yet another ...
    (Vuln-Dev)
  • Re: how do you set a cookie for axshdocvw
    ... I tried to put the cookie string in the header parameter of navigate. ... The tcptrace tool shows that the cookie part of the header is being ... > sqlAuthCookie to the WebBrowser control. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Simple CSS box question
    ... someone with CSS knowledge has a 5-minute solution to my problem... ... I'm trying to create a box with a header, ... The Panel Header should have a left and rigfht margin of 5px and a top ... and should not have a border. ...
    (alt.html)
  • Re: Problems loading CSS files in Mozilla browser
    ... it sounds Mozilla is wanting the Content-type of the CSS header file ... CE Web Server can be configured to send "Content-Type" ... In the Mozilla 1.6 AND the Mozilla Firefox ...
    (microsoft.public.windowsce.embedded)
  • Using CSS to Create a Bank Statement
    ... This section identifies the header section, ... because the "mid" div tag contains a graphic and no text will hang ... the Y axis depending on who the customer is. ... any input would be fine or some css that will acomplish this. ...
    (alt.html)