PluginProbe
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance / 1.1.1
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance v1.1.1
trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4
flying-scripts / source.js

source.js in Flying Scripts: Delay JavaScript to Improve Site Speed & Performance 1.1.1, at source.js

21 lines 673 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const loadScriptsTimer = setTimeout(loadScripts, 5000);
2 const events = ["mouseover", "scroll", "keydown", "touchmove", "touchstart"];
3 events.forEach(function(event) {
4 window.addEventListener(event, triggerScriptLoader, { passive: true });
5 });
6
7 function triggerScriptLoader() {
8 loadScripts();
9 clearTimeout(loadScriptsTimer);
10 events.forEach(function(event) {
11 window.removeEventListener(event, triggerScriptLoader, { passive: true });
12 });
13 }
14
15 function loadScripts() {
16 document.querySelectorAll("script[type='lazy']").forEach(function(elem) {
17 elem.setAttribute("type", "text/javascript");
18 elem.setAttribute("src", elem.getAttribute("data-src"));
19 });
20 }
21