JavaScript: How to check if a file is cached?

My site downloads a rather large js file the first time a user visits it, and I want to write something like "Downloading .. for the first time", this file is not from the cache.

Is this possible in javascript?

+4
source share
2 answers

in js

var loadedMyJS = true 

in your html

  <script > function loadingIndicator(){ document.getElementById('loadingDiv').style.display=''; //to hideit will be 'none' } if(typeof(loadedMyJS) == 'undefined'){ loadingIndicator(); } </script > 
+2
source

How about including a dynamic timestamp at the end and checking it after?

 var t=<?php echo time(); ?>; 

At least I would have been instructed after this fact. Or would I mess up other caching mechanisms by updating the file?

+1
source

All Articles