Overview
A simple JavaScript snippet to detect whether a script has already been loaded on the page.
Originally published on Jang Keyte's Blog.
This article covers Check If a JavaScript File Is Already Included — practical notes from real-world web development experience.
Code Examples
function isScriptAlreadyIncluded(src){
var scripts = document.getElementsByTagName("script");
for(var i = 0; i < scripts.length; i++)
if(scripts[i].getAttribute('src') == src) return true;
return false;
}
Read More
For the full Vietnamese version, switch language using the VI | EN toggle above, or visit the original post.
function isScriptAlreadyIncluded(src){
var scripts = document.getElementsByTagName("script");
for(var i = 0; i < scripts.length; i++)
if(scripts[i].getAttribute('src') == src) return true;
return false;
}
Thanks for reading!