Preventing client-side caching

Posted on 3:46pm 4/25/2008 by Bruno Silva in .NET, ASP.NET, Programming, Web

During this week I’ve been experiencing some problems with browser caching.

I’ve a dynamically generated XML file which contents change a lot (it is a photo gallery based on Slide.Show), and I want the people who see this gallery to see newly added photos immediately. Today someone asked me how to prevent the client-side caching (regarding Slide.Show too), so I did some searches and testing in order to enlight us both. :)

I’ve found reference to a few lines of code which should be used in ASP.NET web pages to prevent caching.

Response.CacheControl = “no-cache”;
Response.AddHeader(”Pragma”, “no-cache”);
Response.Expires = 0;

I tried the first one alone both in IE 7 and Firefox 2 and it seamed to be enough, nevertheless, being care is never enough,so I’ll probably use the 3 lines together!

Just try to be careful and don’t feel tempted to prevent caching in every single web page in your web site, it leads to poor perfomance in both your servers and in the client side. And every one likes to see the content of a previously visited page rendered quickly, right? :)


One Response to “Preventing client-side caching”

  1. Por norma usam-se mesmo as 3 linhas em conjunto. :)

    E costuma-se por o
    Response.Expires = 0;
    a
    Response.Expires = -1;

    (mas o efeito é o mesmo)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Bruno Silva | Powered by Wordpress