Hello friends, I sometimes apply css to my php files but once I update the page what I update of php is reflected but what is related to css no. What can I do about it?
Hello friends, I sometimes apply css to my php files but once I update the page what I update of php is reflected but what is related to css no. What can I do about it?
Hi friends I was looking in google and it worked for me to do this after the styles route:
<link rel="stylesheet" href="css/main.css?v=<?php echo time(); ?>" />
<script src="/js/functions.js?v=<?php echo time(); ?>"></script>
Update the page with CTRL + F5, after a change. Cache usually does those things.
One way to avoid that is to program with calls to the .css with parameters. for example:
<link rel="stylesheet" href="./css/ec_nominas.css?version=1.x.x">
when you publish the application the version will change (obviously 1.xx is a variable), but in development it is better and faster to reload the page by clearing the cache) (with ctrol + f5, or click on refresh with the secondary click and load the page in a forced way)
Forcing the browser to download files that could be in cache, will always affect the loading speed of the page, which hurts the user experience.
Many times, in fact most of the time, there are no changes to these files, so it would be best to reload them only when necessary.
An easy way to control when to force the recharge, is to use a variable under our control instead of the time()
function. For example we could use the variable $version
.
Therefore, when in any of the configuration files, we set the variable $versión
with a different value from the current one, the browser will download the files again, but as long as $version
does not change, you can use them from the cache.
<link rel="stylesheet" href="css/main.css?v=<?= $version ?>" />
<script src="/js/functions.js?v=<?= $version ?>"></script>
This same thing we can use it for images or any other element that can be cached.
<img src="img/cabecera.png?v=?>=$version?>" />
For the browser the name of the image will be different and this will cause it to download it again, instead of using the cached version.
For what it is really good to use a variable type time()
is for ajax calls if the framework does not implement it already serial.