2

I've been making a lot of changes recently and I need a way to force style sheet changes on the client side. Is there a recommended way to do this?

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
Paul
  • 11,671
  • 32
  • 91
  • 143
  • When you say force what do you mean? Change the styles after the page has loaded or reload the modified style sheet? – Andrew Dec 14 '11 at 18:58
  • What do you mean 'style sheet changes on the client side?' Do you mean cached stylesheets? – HellaMad Dec 14 '11 at 18:58
  • What do you mean? Stylesheet changes are reflected when someone views your page, unless there is a style that already trumps the one you added. i.e. if it's more specific, or if there are inline styles, etc. – Catfish Dec 14 '11 at 18:58
  • 2
    Possible duplicate: http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files – bookcasey Dec 14 '11 at 18:59

4 Answers4

4

Add ?v=x.y to the end of the link to your stylesheet.

http://www.zadling.com/2010/08/css-trick-force-users-to-see-new-stylesheet/

Casey Robinson
  • 1,021
  • 9
  • 17
  • If he means he wants to overwrite their cached copy as he makes incremental updates, this is definitely the way to go. – justisb Dec 14 '11 at 19:28
  • It's exactly what I need. Easy yet effective...love it. Thanks! – Paul Dec 14 '11 at 19:37
0

Just send a nocache-header (set it to expire in 1990) and the page should be loaded directly instead of from the cache.

Lars
  • 5,757
  • 4
  • 25
  • 55
0

Add an expires header to your site, but change the value to a date in the past forcing them to redownload the site from scratch and thus clearing there cache,

http://www.askapache.com/htaccess/apache-speed-expires.html

It can be done in apache, php, and others, I would use apache.

cgwebprojects
  • 3,382
  • 6
  • 27
  • 40
0

You could always timestamp or version your CSS, like this:

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

Or with versions

<link rel="stylesheet" type="text/css" href="style.css?ver=2" />
Filip
  • 2,514
  • 17
  • 28