Sie lesen…
Dealing With CSS Caching geschrieben am 16.12.08 von F.Wieser.
In diesem Beitrag werden Themen wie Caching, Css, Webdevelopment besprochen.
Der Autor
Dealing With CSS Caching
I think every web worker has trouble with cached data once in a while and so do we at coUNDco. Recently we had two cases of persistently cached CSS files. Caching depends on the webservers caching policy, but there’s a solution to the problem, regardless of webserver configuration.
What we did was simply appending a GET parameter with a version number to your css file(s), like so:
<link rel=”stylesheet” type=”text/css” ref=”http://somesite.com/css/screen.css?v1.2″ />
respectively with the CSS “import” statement:
@import ‘lib/layout.css?v1.2′;
Now everytime you make changes to the CSS file, you increment the version number. Like this the clients browser thinks it’s a different file and loads the new version.
If you are lazy person like me, you probably don’t want to do this manually every time. In that case you could automatically append the file modification time. With PHP this could look like this:
<link rel=”stylesheet” type=”text/css” ref=”http://somesite.com/css/screen.css?v<?php echo filemtime(’css/screen.css’) ?>” />
The same method can be applied to linked Javascript files.
Keep in mind that caching should be your friend, because it makes your page load faster.
Happy coding!
