I am building my blog by PHP and Godaddy apache server, recently I face a problem that I cannot clear the explorer cache so that each time when I change my style.css I have to change the name of the css file. So can you tell what is wrong or how can I clear the css cache?
8 Answers
You can make the browser automatically clear cache if you create a version based on file modified time
eg:
$filename = '/css/style.css';
$fileModified = substr(md5(filemtime($filename)), 0, 6);
// $fileModified = filemtime($filename); // - with version as timestamp.
and HTML
<link rel="stylesheet" type="text/css" href="<?php echo $filename;?>?v=<?php echo $fileModified ; ?>">
6 Comments
md5 if you can just use filemtime?md5. I've upvoted you because your answer is the most correct among others, but another unnecessary step with md5 still confuses meClear the Browsing History cache in your Browser... This is not related to PHP..
5 Comments
Is this what you asking for?
<link href="style.css?key=<?php echo time(); ?>" type="text/css" rel="stylesheet" />
Best is to keep it like this on your local or testing server only - remove time() part when the site goes live
UPDATE
or instead of time() you could use key=<?php echo date('h'); ?> for hourly or change as you'd like it be.
24 Comments
<link href="style.css?t=[timestamp]" type="text/css" rel="stylesheet">
3 Comments
Use a random number as a parameter with your CSS file. It is one of the easiest way to cache everytime on your browser when file get loaded.
Ex:
style.css?v=12345
4 Comments
For chrome: click on the top right menu button, click on settings, scroll down to advanced and click on it, and click on "Clear browsing data" and tick Cached images and files.
1 Comment
Just press Ctrl+F5 in browser or another combination that update page with clearing cache.