- Content prioritization and optimizing the above the fold render time is what Google's PageSpeed Insights recommends, and makes both your visitors and the search engine's crawlers happy.
How it works
It defers this by changing the
<script> elements on the HTML page to
It also adds a new
type attribute whose value is set
window.onload handler is
added to the HTML, which executes all the deferred scripts.
script tag if it has
pagespeed_no_defer attribute. This is useful when a
script tag needs to be executed while loading the page.
For example, a
script tag may be updating the main content
dynamically as a slideshow of images in the visible content of the page.
Parent variables accessed from an
iframe may be
document.write fail in cases where they span multiple
An example is:
spanwould have been created inside the
spanwould have been created outside and after the
document.body.appendChild calls will always get appended to
the bottom of the page.
completely, such scripts will behave differently with
alert is placed
alert would appear only after the page is loaded completely.
User actions that trigger events such as
onkeypress will not be handled until the page is rendered
pagespeed_no_defer attribute can change the order of script
execution because those scripts using it are executed inline while those not
using are deferred. This can cause errors if these scripts depend on each other
in any way.