The document discusses optimizing the performance of web apps by tracking key metrics like First Paint, First Meaningful Paint, and First Interaction. It explains techniques like inline critical CSS, deferring scripts, browser preloading, server-side rendering, and streaming responses from the server to improve these metrics. Examples are given of how to implement many of these techniques, such as using defer, async, and preload attributes for scripts. Metrics measured before and after optimizations show improvements, with First Interaction decreasing from 6.5s to 4.2s in one case. The document emphasizes the importance of performance tracking and provides resources for further reading on techniques like async script loading.
21. First Interaction
Plain script tags - Download together, execute in order after any pending CSS, blocks
rendering until complete and is itself parse blocking.
3.7s
7.0s
6.5s
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<script src="vendor.js"></script>
<script src="app.js"></script>
<script src="view.js"></script>
</body>
</html>
22. First Interaction
Defer - Download together, execute in order just before DOMContentLoaded.
3.7s
7.0s
6.5s
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<script src=“vendor.js" defer ></script>
<script src=“app.js" defer ></script>
<script src=“view.js" defer ></script>
</body>
</html>
23. First Interaction
Aysnc - Download together, execute in whatever order they download in.
3.7s
7.0s
6.5s
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<script src=“vendor.js" async ></script>
<script src=“app.js" async ></script>
<script src=“view.js" async ></script>
</body>
</html>
24. First Interaction
Source - http://images2.fanpop.com/image/photos/9800000/Chemical-X-powerpuff-girls-movie-9885363-427-320.jpg
3.7s
7.0s
6.5s
25. First Interaction
Async false - Download together, execute in order as soon as all download.
3.7s
7.0s
6.5s
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<script>
[‘vendor.js’,‘app.js','view.js'].forEach( function(src) {
var script = document.createElement('script');
script.src = src;
script.async = false;
document.head.appendChild(script);
});
</script>
</body>
</html>
26. First Interaction
When does the app.js load ?
When does the view.js load ?
When does the componentDidMount of the view gets called (JS interactive) ?
3.7s
7.0s
6.5s
41. First Interaction
Resource : https://css-tricks.com/prefetching-preloading-prebrowsing/
Mandatory and high-priority fetch for a resource that is necessary for the current
navigation
3.7s
7.0s
4.7s
<!DOCTYPE html>
<html lang="en">
<head>
...
<link rel="preload" href=“app.js” as=“script”>
...
</head>
<body>
...
</body>
</html>
70. Metrics to track
defer and async write up
remove 1s from the console.time
change image of dans prefetch
First Interaction to JS enabled
add the streaming images
% improvements
add speed index
read about async=false
read about pre-render
change video
This talk is mostly derived from the experiences and learnings we had while developing our PWA, Housing Go.
So, what are fast or performant apps. What the one thing that comes to one’s mind when talking about fast apps.
Its page load time, Page load time though may not be the accurate indicator or perceived speed but that what is there on top of our mind. The most important factor from which page load time is derived is Critical Rendering Path. You optimize you critical rendering path, you fix your CRP everything will fall into place.
I will show you two versions of this webpage, one version will not be optimized for the critical render path and one version (the page you are reading) is optimized.
What is the critical rendering path?
It is the series of events that must take place to render (display) the initial view of a webpage.
Example: get html > get resources > parse > display webpage
Optimizing these events result in significantly faster webpages.
This is how it looks when a user opens the website on a 3G connection.
By default CSS is treated as a render blocking resource, which means that the browser will hold rendering of any processed content until the CSSOM is constructed. Rendering blocking css can sometimes be the reason for the white screens that we see on browsers.
Let me show you an example. Here the first resource requested in the css for our page. It's the first request as it was in the head at the start. The content Download completed at 3.2s but the browser waits until the css is loaded and parsed to start render, which happens at 4.6s.
This is how it looks when a user opens the website on a 3G connection.
Divide your css into core and noncore, the most important css which is required for the content to be shown to user, is inlined.
Divide your css into core and noncore, the most important css which is required for the content to be shown to user, is inlined.
This is a webpage test with inline css show that the content downloaded still gets completed at around 3.1 seconds, even though the doc size is increased. The improvement is that start render happens at around 3.5s, improvement of about 1s.
By default CSS is treated as a render blocking resource, which means that the browser will hold rendering of any processed content until the CSSOM is constructed. Rendering blocking css can sometimes be the reason for the white screens that we see on browsers.
In modern SPAs it's important to maintain separate chunks of JS files and at the same time download and execute them synchronously. In context of housing.com there are generally 3 files that we load for our app to work. General download techniques are as follows.
Spec says: Download together, execute in order after any pending CSS, block rendering until complete.
Browsers say: Yes sir!
Spec says: Download together, execute in order just before DOMContentLoaded. Ignore “defer” on scripts without “src”.
IE < 10 says: I might execute 2.js halfway through the execution of 1.js. Isn’t that fun??
Other browsers say: Ok, but I might not ignore “defer” on scripts without “src”.
Spec says: Download together, execute in whatever order they download in.
The browsers in red say: What’s ‘async’? I’m going to load the scripts as if it weren’t there.
Other browsers say: Yeah, ok.
What is the real solution .. putting JS at the bottom of the page.
Spec says: Download together, execute in order as soon as all download.
http://www.html5rocks.com/en/tutorials/speed/script-loading/
async = false telll the browser to not execute the scripts asynchronously and in order they are added
dynamically generated scripts do not block rendering
explain html async=false
How does talk console.time works.
Mention about vendor.js and manifest.js ,
Mention about vendor.js and manifest.js
Mention about vendor.js and manifest.js
Loading scripts this way is supported by everything that supports the async attribute, with the exception of Safari 5.0 (5.1 is fine). Additionally, all versions of Firefox and Opera are supported as versions that don’t support the async attribute conveniently execute dynamically-added scripts in the order they’re added to the document anyway.
When the browser is blocked on a script, a second lightweight parser scans the rest of the markup looking for other resources e.g. stylesheets, scripts, images etc., that also need to be retrieved.
The pre-loader then starts retrieving these resources in the background with the aim that by the time the main HTML parser reaches them they may have already been downloaded and so reduce blocking later in the page.
Pre-loaders extract URLs from markup and don’t / cannot execute javascript so any URLs inserted using javascript aren’t visible to it.
When the browser is blocked on a script, a second lightweight parser scans the rest of the markup looking for other resources e.g. stylesheets, scripts, images etc., that also need to be retrieved.
The pre-loader then starts retrieving these resources in the background with the aim that by the time the main HTML parser reaches them they may have already been downloaded and so reduce blocking later in the page.
Pre-loaders extract URLs from markup and don’t / cannot execute javascript so any URLs inserted using javascript aren’t visible to it.
Mandatory and high-priority fetch for a resource that is necessary for the current navigation
By default CSS is treated as a render blocking resource, which means that the browser will hold rendering of any processed content until the CSSOM is constructed. Rendering blocking css can sometimes be the reason for the white screens that we see on browsers.
Divide your css into core and noncore, the most important css which is required for the content to be shown to user, is inlined.
Divide your css into core and noncore, the most important css which is required for the content to be shown to user, is inlined.
Divide your css into core and noncore, the most important css which is required for the content to be shown to user, is inlined.