Conditionally load JavaScript file

You’d have to create that markup yourself in JS. Something like this:

var head = document.getElementsByTagName('head')[0];
var js = document.createElement("script");

js.type = "text/javascript";

if (screen.width > 500)
{
    js.src = "https://stackoverflow.com/questions/15521343/js/jquery_computer.js";
}
else
{
    js.src = "https://stackoverflow.com/questions/15521343/js/mobile_version.js";
}

head.appendChild(js);

Leave a Comment