开发者

JavaScript: How can I check whether a file is cached?

开发者_如何学CMy site loads a pretty large js file the first time a user visits, and I want to write something like "Loading .. for the first time" it the file isn't from cache.

Is this possible in javascript?


in your 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 >


What about including a dynamic timestamp at the end, and checking it afterwards?

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

At least i'd get an indication after the fact. Or would I mess up other caching mechanisms by updating the file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜