PluginProbe
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance / 1.1.4
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance v1.1.4
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.4, at source.js

27 lines 730 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 userInteractionEvents = [
3 "mouseover",
4 "scroll",
5 "keydown",
6 "touchmove",
7 "touchstart"
8 ];
9 userInteractionEvents.forEach(function(event) {
10 window.addEventListener(event, triggerScriptLoader, { passive: true });
11 });
12
13 function triggerScriptLoader() {
14 loadScripts();
15 clearTimeout(loadScriptsTimer);
16 userInteractionEvents.forEach(function(event) {
17 window.removeEventListener(event, triggerScriptLoader, { passive: true });
18 });
19 }
20
21 function loadScripts() {
22 document.querySelectorAll("script[type='lazy']").forEach(function(elem) {
23 elem.setAttribute("type", "text/javascript");
24 elem.setAttribute("src", elem.getAttribute("data-src"));
25 });
26 }
27