0

In an post of Dynamic CSS - caching problem? it was stated to add ?value to the end of the css file name to assist in caching. I am using themes and the css files are loaded automatically. Can an HttpHandler be used to modify the css file path before rendering?

Any examples or links of how this could be accomplished?

Community
  • 1
  • 1
econner
  • 707
  • 2
  • 8
  • 14
  • I assume you're using a .NET language. It would help tagged the question with the language. – Michael Mior Aug 16 '11 at 02:53
  • this post may be helpful - http://stackoverflow.com/questions/1234246/random-querystring-to-avoid-ie-caching – MikeM Aug 16 '11 at 03:16
  • Actually, I am looking for more information on how to handle this thru an HttpHandler. The reason is due to the ASP.Net themes process loads the css files automatically from the directory associated to the theme. The css links are created automatically and use the file name of each css file. I would like to intercept this thru the handler and append the ?value to the link before the page is rendered. – econner Aug 16 '11 at 13:11

1 Answers1

1

Assuming usage of PHP, you could do this; however, this can be adapted pretty easily to any language.

<?php
$randNum = mt_rand();
?>

<link type="text/css" rel="stylesheet" href="style.css?<?=$randNum?>" />

Here's a demo of it: http://wecodesign.com/demos/stackoverflow-7072702.php

UPDATE You could also set your headers to prevent caching, in the case of a CSS file, you'd need to do something like this at the top of your CSS, which would be renamed with a php extension instead of a css extension:

<?php
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
?>