<link>
in the <head>
Putting style sheets near the bottom of the document is what prohibits progressive rendering in many browsers. Some browsers block rendering to avoid having to repaint elements of the page if their styles change.
<script>
just before </body>
<script>
tags block HTML parsing. Placing the scripts at the bottom will allow the HTML to be parsed and displayed to the user first.
Set image’s
data-set
attribute as image path. Since it isn’tsrc
, it won’t send http request. Then calculate the sum of page’sscrollTop
height and browser’s height. If the distance between image’s Y position and page’s top is less than the sum, turn thedata-set
tosrc
.
- Prioritizing visible content
- Async HTML fragments
translate()
instead of absolute
Changing transform
or opacity
does not trigger browser reflow or repaint but does trigger compositions(排列); whereas changing the absolute positioning triggers reflow.
When using translate
, the element still occupies its original space, unlike in changing the absolute positioning.