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

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