john doe
john doe

Reputation: 9660

Checking if the JavaScript File has already been downloaded

If the same Javascript file has different URL's then is it possible to find out that if the JavaScript file has already been downloaded. Not using the URL but using the name of the file.

Is this possible using JavaScript?

Upvotes: 1

Views: 170

Answers (2)

Nicolas Albert
Nicolas Albert

Reputation: 2596

If you defined a variable in the script, you can check if the variable is already defined:

if (typeof(myScriptDefined) == "undefined") {
    myScriptDefined=true;
    // rest of my script content
}

Upvotes: 1

animatedgif
animatedgif

Reputation: 1109

You could find all <script> elements in the DOM and check if any src attributes match the regex of the filename.

Upvotes: 0

Related Questions