14
Html from request to rendering @toan

Html from request to rendering

Embed Size (px)

Citation preview

Page 1: Html from request to rendering

Html from request to rendering

@toan

Page 2: Html from request to rendering

Content

1. Resources loading.2. Critical rendering.3. Optimizing performance.

Page 3: Html from request to rendering

Resources loading

image credit: https://developer.chrome.com/devtools/docs/network

Page 4: Html from request to rendering

Resources loading

Page 5: Html from request to rendering

Resources loading

* Blue line is dom content loaded event and red line is loaded event=> We must block and wait for CSS (CSSOM) before we can execute JavaScript

eg1) With only images:

eg2) With images + javascript + css

Page 6: Html from request to rendering

Resources loading

* As soon as the browser hits the script tag it will block (DOM) and wait until the CSSOM is constructed.

eg3) Change external script to inline script

Page 7: Html from request to rendering

Resources loadingeg4) Async (external) JavaScript

eg5) Inlined both the CSS and JavaScript

<script src="timing.js" async></script>

Page 8: Html from request to rendering

Critical rendering

image credit https://developers.google.com/web/fundamentals/performance/critical-rendering-path/

Page 9: Html from request to rendering

Critical renderingUsing extend js to query cssom -> the browser will pause until “style.css” is downloaded and CSSOM is constructed.

Page 10: Html from request to rendering

Critical renderingMaking the script asynchronous

<script src="app.js" async></script>

Page 11: Html from request to rendering

Making the script asynchronous & css stylesheet was only needed for print

<script src="app.js" async></script><link href="style.css" rel="stylesheet" media="print">

Critical rendering

Page 12: Html from request to rendering

Optimizing performance.- Avoid Landing Page Redirects- Minify, compress, cache.- Make fewer requests- CSS blocks rendering -> put on top- JS blocks downloads -> put on bottom.

- Use media queries on link to unblock rendering. Usually means breaking CSS into media-applicable pieces

<link rel="stylesheet" type="text/css" media="only screen and (max-width: 480px)" href="small-device.css" />

- Inline CSS. if the external CSS resources are small.- Avoid CSS @imports

Page 13: Html from request to rendering

Optimizing performance.- Defer Javascript execution.- use async attribute on script.- new fetch() method provides an easy way to asynchronously request data.