Issue
I have been programming with Visual Studio, but when I make changes in CSS or other files, the browser load the last cache page and I must clean cache manually every single test. So I have been trying to clean the cache first but PHP headers doesn´t work.
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: application/xml; charset=utf-8");
exit;
?>
I have placed the php code
before and after <!DOCTYPE html>
before and after <html>
tag
before and after <header>
tag
before and after <body>
tag
According to php manual site
Remember that
header()
must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
this means that it must be placed before the html tag. but this gives me the error:
show this error:
This page contains the following errors:
error on line 4 at column 1: Start tag expected, '<' not found
Below is a rendering of the page up to the first error.
If I delete the headers the code works fine
in chrome browser.
Also triyed the function:
clearstatcache(bool $clear_realpath_cache = false, string $filename = ""): void
But it doesn't work or I don't how or where to implement.
Solution
To prevent the browser from using cached css or js files during development of a website, you need to provide the browser with a 'new' file for it to load each time.
Using PHP you can append a dynamic parameter to the URL. You can use rand(), date(), uniqid(), or any other function to create a new value each time.
<link rel="stylesheet" href="styles.css?version=<?php echo rand(); ?>">
Answered By - Jacob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.