'How to dynamically load a CSS file avoiding navigator cache

I've usually loaded CSS files with PHP by adding a GET variable that changes each time. For example the value of the microtime

But I need to dynamically load a CSS file avoiding navigator cache for see the continuous changes making in production development.

<?php echo '<link rel="stylesheet" type="text/css" href="myFile.css?v='.round(microtime(true)).'"></script>';?>


Solution 1:[1]

Sometimes you will need to load a dynamic file name as well. It is possible to do it without PHP like this:

<link rel="stylesheet" type="text/css" href="" id="myCSS">

<script>     
  var microTime = Date.now();   
  var myVar = "myCSSFile";
  var myUrl = myVar+'.css' + '?v=' + microTime;

  myCSS.href= myUrl;
</script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JTCon