Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

51
Views
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>';?>
7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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>
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.