An average user stays in your site if the page loads in < 1000ms. In 2014, an average page size is 1.9MB. See the below chart for more stats.

via source httparchive
The core content of site should render with in 1000ms
. If it fails, then the user is never gonna come back to your site again. By improving page load time, the revenue and downloads increased tremendously for many popular companies.
- Let's take Walmart for every
100ms
of improvement to their site, they grew revenue up to1%
- Yahoo traffic increased by
9%
for every400ms
of improvement. - Mozilla speed up their site by
2.2sec
gave them160 million
more firefox downloads/year.
Steps involved in site optimization:
-
Set performance budget.
-
Measuring the current performance.
-
Find the problem causing performance issue.
-
And finally yay, optimize it.
There are several ways to optimize your site, Lets see about it
Speed Index
Speed index is the average time at which visible parts of page is painted in the browser. Expressed in milliseconds and also depends on the viewport size. See below image ( video frames to show web page load at seconds ).
Lower speed index score is the better score.

Speed index can be measured by using Webpagetest (maintained by google).
TL;DR
Webpage test has lots features like running multiple test in different locations using different browsers. And can measure other metrics like load time, number of DOM elements, first byte time etc..
Eg: checkout the measured result of amazon here using webpagetest.
Watch the below video by Patrick Meenan to know more about webpagetest
Render Blocking
If you know how a browser works, then you know about how HTML, CSS, JS
are parsed by browser and which is blocking the rendering of the page. If you don't, see the below simple diagrammatic representation below.

Read more about how a browser works written by Tali Garsiel and Paul Irish.
Steps involved in rendering in a browser:
- First browser parses
HTML
markup to constructDOM tree
( DOM = Document Object Model ) - Then parses
CSS
to constructCSSOM tree
( CSSOM = CSS Object Model ) - Before combining both DOM and CSSOM tree to contruct Render tree,
JS
files are parsed and executed.
Now you understood how parsing is done in a browser. Lets see which is blocking the construction of rendering tree.
Render-Blocking CSS
CSS is treated as render blocking. For the construction of CSSOM, all the CSS are downloaded regardless of whether they are used in current page or not.
To solve this render-blocking, go through below steps
- Inline the critical CSS, that is most important styles used by page above the fold in head tag inside
<style></style>
- Remove the unused CSS.
So how do I find unused CSS.
-
Use Pagespeed Insight to get stats like unused CSS, render-blocking CSS and JS files etc.
Eg: Flipkart's Pagespeed Insight result here.
-
Gulp tasks like gulp-uncss or use Grunt tasks like grunt-uncss. If you don't no what is grunt or gulp, read my previous post.
ProTips
- Use CSS Stats to get total no of elements used, no of unique styles, fonts etc.
- Pagespeed Insight Chrome Extention.
- Tag Counter Chrome Extention.
Render-Blocking Javascript
If the browser encounter's javascript while parsing the HTML markup
, the parsing is stopped. Only after executing the script, the HTML rendering will be continued. So this block's the rendering of the page
.
To solve this
Use async
or defer
attribute in <script></script>
tag.
<script async>
will download the file during theHTML parsing
and execute it as soon as the file is downloaded.<script defer>
will download the file during theHTML parsing
and will execute it afterHTML parsing
is completed.
Note:
async and defer
both are used in Google Analytics
Browser support for async and defer.
Memory Leaks
Memory leaks
and Bloat is one of the problems faced by web developers. Lets see how to find a memory leak and later solve them.
Lets find Memory Leak in Javascript####
- Using Chrome Task Manager to check
memory used by app
as welljs memory
(total + live memory). If your memory keeps on growing on each action, then you can suspect there is a memory leak.
See below the screenshot of Chrome Task Manager:

Chrome DevTools Profiling
Use Heap Profiler
to find memory leak. Open chrome devTools and go to profiles tab and select take heap snapshot.
If you don't know about chrome DevTools, read my previous post.
Screenshot for Chrome DevTools Profiler

The Heap Profiler has 4 snapshot views
- Summary View - To show total number of objects allocated and its instance,
Shallow Size
(size of the memory of obj itself) andRetained Size
(size of the memory that will be freed once automatic GC happens + unreachable object). - Comparison View - To compare two or more snapshots before and after a operation to check memory leak.
- Containment View - To show overall view of your app object structure + DOMWindow Objects (that is global obj's), GC roots, Native objects (from the browser).
- Dominators View - This will show the dominators tree of a heap graph.
Read more in detail about Heap profiler.
DOM Leaks:
Reference to DOM elements
causes DOM Leak and prevents automatic garbage collection(GC) process.
Lets see an example
<div id="container">
<h1 id="heading">I am just a heading nothing much</h1>
</div>
var parentEle = document.getElementById('container'); //get parent ele reference
var headingEle = document.getElementById('heading'); //get child ele reference
parentEle.remove(); //removes parent element from DOM
//but its child ref still exist, So parentEle won't collect GC'd and causes DOM Leak
Let's fix this DOM leak by making its reference null
headingEle = null; //Now parentEle will be GC'd
The above are common problems faced by web developers. Thats all for today. If you like my post share it or have a doubt comment below. Thanks!!