Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to defer javascript-mod-pagespeed in javascript?


Asked by Winston Schultz on Dec 06, 2021 JavaScript



It defers this by changing the type and src attributes of <script> elements on the HTML page to data-pagespeed-orig-type and data-pagespeed-orig-src respectively. It also adds a new type attribute whose value is set to text/psajs. A window.onload handler is added to the HTML, which executes all the deferred scripts.
Similarly,
The effect of this filter can be observed on modpagespeed.com before and after rewriting. Parent variables accessed from an iframe may be undefined when defer_javascript is used. All JavaScript code is downloaded and executed serially, whereas without defer_javascript the browser tries to download JavaScripts in parallel as much as possible.
And, The 'Defer JavaScript' filter is enabled by specifying: in the configuration file. Warning: Defering JavaScript can often dramatically improve the rendering speed of a site, but careful evaluation is required to ensure the site continues to operate properly. The limitations are described below.
Thereof,
defer_javascript tries to defer JavaScript execution until page load. It defers this by changing the type and src attributes of <script> elements on the HTML page to data-pagespeed-orig-type and data-pagespeed-orig-src respectively. It also adds a new type attribute whose value is set to text/psajs.
Furthermore,
The data-pagespeed-no-defer attribute can change the order of script execution because those scripts using it are executed inline while those not using it are deferred. This can cause errors if these scripts depend on each other in any way.