dynamic stylesheet problem

P

Puja

hi all,

On my page, i have external stylesheet
<link id="sbSiteCSS" rel="stylesheet" type="text/css" runat="server" />

whose href is determined on page_load
protected void Page_Load(object sender, EventArgs e)

{

sbSiteCSS.Attributes.Add("href", "http://www.mydomain.com.au/1/site.css?"
+ DateTime.Now);

}

I have added DateTime Attribute at the end so that every time my external
stylesheet is changed, browser loads new version of same stylesheet.

Now my problem is if I change few things in my stylesheet, it is not
reflected on my page even when I have added DateTime attribute at the end.
Browser seems to cache my stylesheet and keep on displaying same.

How do I get around this problem ?

Thanks

puja
 
N

Nicholas Paldino [.NET/C# MVP]

Puja,

In adding the DateTime at the end of the url as part of the query
parameter, you aren't changing any of the attributes of the item which
affect how it is cached.

There are a few options to get around caching. The first would be with
the naming of the css page. You could put the date/time the css page is
valid in the css name, like so:

http://www.mydomain.com/1/site.20070613.css

And then have a central area where the name of the css page is stored,
writing the value dynamically to your pages.

The second is to make your css page an ASP.NET page. That should
disable caching in any form by default, but it's going to add overhead to
your page rendering, as the css page will probably be loaded every single
time (which you don't want to do if the changes are infrequent).

I think the naming convention is the better solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top