Skip to content

Instantly share code, notes, and snippets.

@molotow11
Created February 15, 2021 10:37
Show Gist options
  • Save molotow11/c8c33e7d5320094757f01c60c5548ce8 to your computer and use it in GitHub Desktop.
Save molotow11/c8c33e7d5320094757f01c60c5548ce8 to your computer and use it in GitHub Desktop.
Defer scripts loading
var scriptsLoadDelay = 10000;
var delayedScripts = [
"https://w.sharethis.com/button/buttons.js",
];
setTimeout(function() {
console.log("Delayed scripts loading");
for(var i=0; i<delayedScripts.length; i++) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = delayedScripts[i];
console.log("Delayed: " + delayedScripts[i]);
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(script, s);
}
}, scriptsLoadDelay);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment