When I’m writing CSS code for a webpage, I use a JavaScript plugin which uses Ajax to check whether a CSS file has been edited every second by checking the CSS file’s Last-Modified
header. If a CSS file has been edited, the JavaScript plugin forces my browser to reload the CSS file. That’s convenient because it saves my efforts to manually refresh my browser for seeing the applying of my style changes.
The JavaScript plugins works perfectly fine for regular stylesheet files such as style.css. But it does not work for PHP stylesheet file such as style.php. After my investigation, I found that the culprit is style.php lacks the Last-Modified
header.
The beginning of my style.php is:
<?php
header('Content-Type: text/css; charset=UTF-8');
header('Cache-Control: max-age=315360000');
header('Expires: Thu, 5 April 2035 00:00:00 GMT');
?>
The Cache-Control
and Expires
headers are for forcing browsers to cache style.php.
Theoretically, I can solve the issue by adding the fourth header which would be the Last-Modified
header, and then manually update the Last-Modified
header every time I edited style.php. But practically, that completely defeats the purpose of using the JavaScript plugin.
It also puzzles me that a regular CSS stylesheet such as style.css is able to automatically provide an updated Last-Modified
header, while a PHP stylesheet such as style.php fails to do so.
So my question is: Is it possible to make style.php automatically provide an updated Last-Modified
header like regular stylesheet files such as style.css does?