fix for stubborn browsers cache and css files

Hi, sorry but I didn’t know how to use this code. My code looks like this:
<link rel=“stylesheet” href=‘styles/header.css?<?php echo filemtime($_SERVER["DOCUMENT_ROOT"] . "styles/header.css"); ?>’ / and > at the end
My file is php and there are no problems in the console, can you help me?

try this

<link rel='stylesheet' href='/styles/header.css?<?php echo filemtime($_SERVER["DOCUMENT_ROOT"] . "/styles/header.css"); ?>' />

im assuming that your styles directory is in the htdocs root directory
basically the full directory path is required


I have found a solution, you don’t have to change extension of index.html to .php

Solution -

Add version number and increment it every time you make changes to css. Sample code is right below. Check it. Worked for me anyway!

Sure, that is a good idea if your website is static. But if your website is dynamic and uses PHP a lot, then why not?

You could also do what Oxy suggested:


To clarify, you mean the file inside the /htdocs folder, yeah? And would it be okay if I only have these lines, and nothing else? (:

I am having a “stubborn cache” issue, and would rather not change my actual files. It seems I need to always use hard-refresh (Ctrl+Shift+R) to see the actual, updated index.html of my website…

I found that even after ctrl-shift-r that my firefox browser would still display the cached .css file instead of my recent changes which forced me to think of this filetime solution :frowning:

firefox can be annoying sometimes