Why are CSS styles not updated?

0

It happens to me sometimes that I have to eliminate the datos de navegación , cookies , caché , and everything so that I just update the styles that you modify in CSS , which are in another folder as you already know. I use IDE NeatBeans and server Apache (XAMPP) .

    
asked by henrry holmes paytan carreño 09.07.2018 в 10:44
source

2 answers

1

If you are working on the website continuously and need to refresh the CSS and JS changes without being cached, there are some options.

You can place the following in the header:

<head>
  <meta http-equiv="Expires" content="0">
  <meta http-equiv="Last-Modified" content="0">
  <meta http-equiv="Cache-Control" content="no-cache, mustrevalidate">
  <meta http-equiv="Pragma" content="no-cache">
</head>

If your application is working on php you can also use:

<?php
  header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  header("Expires: Sat, 1 Jul 2000 05:00:00 GMT"); // Fecha en el pasado
?>

Now, this system will work for you if you are constantly editing the styles or scripts and you need to see results at the moment.

Another solution

Perhaps the most successful solution is to generate versions of the styles or js using ?123 . For example, we generate a random number in php and assign it to the file:

<link rel="stylesheet" href="/css/mi_estilo.css?v=<?php echo(rand()); ?>" />
<script src="/js/mi_script.js?v=<?php echo(rand()); ?>"></script>
    
answered by 09.07.2018 / 12:13
source
2

The best thing you can do is add the date in Unix format, after the file path, like this:

<link rel="stylesheet" href="/css/styles.css?v=<?php echo time(); ?>" />
<script src="/js/functions.js?v=<?php echo time(); ?>"></script>

In this way, you avoid that if a randomly generated number is (casually) repeated, you will not load an archive version stored in the browser's cache.

    
answered by 09.07.2018 в 12:45