Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear css cache

Tags:

css

php

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?

like image 805
Ben G Avatar asked Oct 19 '25 08:10

Ben G


2 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 ; ?>">
like image 165
Mihai Iorga Avatar answered Oct 20 '25 22:10

Mihai Iorga


Put Version Number for your css file like following,

style.css?v=1 or style.css?v=1.1
like image 39
Amar Gharat Avatar answered Oct 20 '25 22:10

Amar Gharat