Mike
Mike

Reputation: 51

CSS browser caching

Is there a possibilty of caching when a css file is added like this:-

<link rel='stylesheet' type='text/css' href='rstyle_sheet.css'>

as changes done in that file are not getting reflected immediately.

If Yes, Any way to counter that..?

Upvotes: 0

Views: 764

Answers (5)

WB Lee
WB Lee

Reputation: 841

in Mac, use command+shift+r to force refresh page.

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346260

CSS stylesheets referred to that way are cached like every other resource, be it HTML pages, Javascript files or images.

And like every other resource, you can influence the caching behaviour via the HTTP headers Expires: and Cache-Control:. That means you either have to change the webserver configuration, or have the CSS files served by a PHP script rather than as plain text.

Upvotes: 0

Niels Bom
Niels Bom

Reputation: 9377

If you are developing and don't want the cached version turn off caching in your browser.

I use the following combination of tools: Firefox + Web Developer Toolbar and then Disable > Disable Cache

Upvotes: 0

Joelio
Joelio

Reputation: 4691

Yes, add a timestamp after the css file name, like this:

<link rel='stylesheet' type='text/css' href='rstyle_sheet.css?1312843018'>

And update the timestamp each time you change the file. Lots of frameworks like ruby on rails etc do this for you

Upvotes: 0

Jayne Mast
Jayne Mast

Reputation: 1487

Most browsers cache CSS
You could add a version number to prevent it:

<link rel='stylesheet' type='text/css' href='rstyle_sheet.css?v=2'>

Upvotes: 1

Related Questions