PluginProbe
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance / 1.2.0
Flying Scripts: Delay JavaScript to Improve Site Speed & Performance v1.2.0
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 / inject-js.php

inject-js.php in Flying Scripts: Delay JavaScript to Improve Site Speed & Performance 1.2.0, at inject-js.php

12 lines 879 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function flying_scripts_inject_js() {
4
5 $timeout = esc_attr(get_option('flying_scripts_timeout'));
6 ?>
7 <script type="text/javascript" id="flying-scripts">const loadScriptsTimer=setTimeout(loadScripts,<?php echo $timeout ?>*1000);const userInteractionEvents=["mouseover","keydown","touchmove","touchstart"];userInteractionEvents.forEach(function(event){window.addEventListener(event,triggerScriptLoader,{passive:!0})});function triggerScriptLoader(){loadScripts();clearTimeout(loadScriptsTimer);userInteractionEvents.forEach(function(event){window.removeEventListener(event,triggerScriptLoader,{passive:!0})})}
8 function loadScripts(){document.querySelectorAll("script[data-type='lazy']").forEach(function(elem){elem.setAttribute("src",elem.getAttribute("data-src"))})}</script>
9 <?php
10 }
11
12 add_action( 'wp_print_footer_scripts', 'flying_scripts_inject_js');