SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Prioritize Your Critical CSS and Images

WebRTCfast
to render your site
Jan-Willem Maessen

PageSpeed Optimization Library
Google
jmaessen@google.com
Prioritizing Critical CSS and Images Makes Render Fast

jmaessen@google
Inline critical CSS in <head>
Inline low res visible images
Lazy load everything else
jmaessen@google
Users Expect Speed
Delay

User reaction

0 - 100 ms

Instant

100 - 300 ms

Slight perceptible delay

300 - 1000 ms

Task focus, perceptible delay

1 s+

Mental context switch

10 s+

I'll come back later...

Our pages
should render in
1000 ms or less
Website Abandonment (Strangeloop)

Ilya Grigorik (Go to his talk)
BUT
jmaessen@google
Mobile web performance is
crippled by network latency
We need to build fast pages for today’s devices

jmaessen@google
Network Performance Varies Even in the Lab

jmaessen@google
Optimistic But Useful Model of HTTP Connection
What is Happening

Time

Total data

(200 ms RTT)

(KB)

Control plane (200-2500 ms)

–

DNS lookup

200 ms

–

TCP Connection

400 ms

–

First 10 packets (15K)

600 ms

14K

Next 20 packets (29K)

800 ms

Next 40 packets (44K)

1000 ms

If your site is reached via a mobile
redirect, you’re already down here.
Time

Total data

(200 ms RTT)

(KB)

TCP DNS lookup
Connection

800 ms

–

44K

First 10 packets (15K)
TCP Connection

1000 ms

14K
–

88K

First 10
(15K)
Next 20 packets (29K)

1200 ms

44K
14K

40
(44K)
Next 20 packets (29K)

1400 ms

88K
44K

Next 40 packets (44K)

1600 ms

88K

Actually, all these numbers exceed the
384Kbit/s (48K/s) bandwidth of old 3G
networks.

Resource request
(original host)
(second

jmaessen@google
We don't need to render the entire page...

We need to render above the fold content!

1. One RTT render for above the fold!
2. No redirects + fast server response (<200 ms)
3. Must optimize critical rendering path
a. Inline critical CSS
b. Remove blocking JavaScript
c. Prioritize above-the-fold images

@igrigorik
Why can’t the browser do this?
What CSS will affect the above the fold HTML?
What HTML will be above the fold after styling?
How large is each above the fold image?
Will JavaScript affect the content of the DOM?

jmaessen@google
Step 1: Prioritize Your Critical CSS

jmaessen@google
Let's look at that simple example...
prioritize_critical_css.html
styles/blue.css
<!doctype html>
<html>
<head>
<title>prioritize_critical_css example</title>
<link rel="stylesheet" href="styles/blue.css">
<link rel="stylesheet" href="styles/big.css">
<style>
@import url(styles/all_using_imports.css);
</style>
<link rel="stylesheet" href="
styles/rewrite_css_images.css">
</head>
<body>
<div class="foo" style="display:inline-block;"></div>
<span class="blue big">Prioritize Critical CSS</span>
…<body>

.blue {color: blue;}
styles/big.css

.big { font-size: 8em; }
.very_large_class… { font-size: 8em; }
…(lots more unused rules)
styles/all_using_imports.css

@import url(yellow.css);
@import url(blue.css);
@import url(bold.css);
styles/rewrite_css_images.css

.foo {
background-image:
url(../images/BikeCrashIcn.png);
width: 100px;
height: 100px;
}

jmaessen@google
What happens when the browser loads our page
prioritize_critical_css.html
styles/blue.css
<!doctype html>
<html>
<head>
<title>prioritize_critical_css example</title>
<link rel="stylesheet" href="styles/blue.css">
<link rel="stylesheet" href="styles/big.css">
<style>
@import url(styles/all_using_imports.css);
</style>
<link rel="stylesheet" href="
styles/rewrite_css_images.css">
</head>
<body>
<div class="foo" style="display:inline-block;"></div>
<span class="blue big">Prioritize Critical CSS</span>
…<body>

styles/big.css
styles/all_using_imports.css

@import url(yellow.css);
@import url(blue.css);
@import url(bold.css);
styles/rewrite_css_images.css

.foo {
background-image:
First render:
url(../images/BikeCrashIcn.png);
width: 100px;
height: 100px;
}

1.8s

jmaessen@google
Inline the CSS that is actually used on the page
prioritize_critical_css.html
<!doctype html>
<html>
<head>
<title>prioritize_critical_css example</title>
<style>.blue{color:blue}</style>
<style>.big{font-size:8em}</style>
<style>.blue{color:blue}.bold{font-weight:bold}</style>
<style>.foo{background-image:url(images/BikeCrashIcn.png);
width:100px;height:100px}</style>
</head>
First render:
<body>
<div class="foo" style="display:inline-block;"></div>
<span class="blue big">Prioritize Critical CSS</span>
…<body>

0.7s

jmaessen@google
Simplest Option: Just Inline All the CSS
● Around 40% of the CSS rules are used in a typical page
● Tweaking a PHP script to inline all the CSS should be easy
● Warning: 44K of compressed CSS on typical page
As always, test and measure – do what the data tells you
for your site.

HTTP Archive data on CSS sizes

jmaessen@google
Identify critical CSS via an Audit

(Manual)

DevTools > Audits > Web Page Performance
Inline the critical styles...
@igrigorik
Let PageSpeed Find Critical CSS Automatically
ModPagespeedEnableFilters prioritize_critical_css

# Apache

pagespeed EnableFilters

# Nginx

prioritize_critical_css;

Instrumented
Page

PageSpeed
Server

Beacon result:
List of critical selectors
Client
Browser

Downside: first access to the page won’t be optimized.
Upside: will be based on actual client browser behavior
jmaessen@google
Rules That Are Triggered by JavaScript Actions
Option 1: Include them in your critical CSS
● Careful: they may not necessarily show up in an audit!
Option 2: Lazyload them
● Load before we run the relevant JavaScript
● Lazyload also works for non-screen styles (eg print)

jmaessen@google
How Not to Lazy Load CSS
prioritize_critical_css.html
<!doctype html>
<html>
<head>
<title>prioritize_critical_css example</title>
…
</head>
<body>
<div class="foo" style="display:inline-block;"></div>
<span class="blue big">Prioritize Critical CSS</span>
…
<link
<link
<link
<link

rel="stylesheet"
rel="stylesheet"
rel="stylesheet"
rel="stylesheet"

href="styles/blue.css">
href="styles/big.css">
href="styles/all_using_imports.css">
href="styles/rewrite_css_images.css" media="all">

The browser will notice
the stylesheets when it
reaches the bottom of
the page and block
rendering –
It can’t tell that none of
the rules will apply to
the page.

</body>
</html>
jmaessen@google
How PageSpeed Optimization Library Lazy Loads CSS
prioritize_critical_css.html
<!doctype html>
<html>
<head>
<title>prioritize_critical_css example</title>
…
</head>
<body>
<div class="foo" style="display:inline-block;"></div>
<span class="blue big">Prioritize Critical CSS</span>
…
<noscript class="psa_add_styles">
<link rel="stylesheet" href="styles/blue.css">
<link rel="stylesheet" href="styles/big.css">
<link rel="stylesheet" href="styles/all_using_imports.css">
<link rel="stylesheet" href="styles/rewrite_css_images.css" media="all">
</noscript>
<script>...Move <noscript> to a div...</script>
</body>
</html>

The noscript block
keeps the browser from
downloading the CSS
until the script runs.
This blocks rendering
when JS is switched off
But the page continues
to work correctly
You can skip this for
non-screen media=
attributes.
jmaessen@google
Step 2: Lazy Load Below the Fold Images

jmaessen@google
Another very simple example...
lazyload_images.html
<!doctype html>
<html><head>...</head>
<body>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png"><br/>
<p>*</p> <p>*</p>
<p>Should be below the fold...</p>
<p>*</p> <p>*</p>
<img src="images/Puzzle.jpg"><br/>
<img src="images/IronChef2.gif"><br/>
<img src="images/Cuppa.png"><br/>
</body> </html>

images/BikeCrashIcn.png

images/Puzzle.jpg

images/IronChef2.gif

images/Cuppa.png
jmaessen@google
Lazyloading All the Images
lazyload_images.html
<!doctype html>
<html><head>...</head>
<body>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<script>...lazyload code...</script>
<img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p>
<p>Should be below the fold...</p>
<p>*</p> <p>*</p>
<img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/>
<img lazy_src="images/IronChef2.gif" width="192" height="256"><br/>
<img lazy_src="images/Cuppa.png" width="65" height="70"><br/>
jmaessen@google
Include Dimensions with Lazy Loaded Images

Without image dimensions (left), page reflows on image load
jmaessen@google
Don’t Lazy Load Images Above the Fold!
lazyload_images.html
<!doctype html>
<html><head>...</head>
<body>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img src="images/BikeCrashIcn.png" width="100" height="100"><br/>
<p>*</p> <p>*</p>
<p>Should be below the fold...</p>
<p>*</p> <p>*</p>
<script>...lazyload code...</script>
<img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/>
<img lazy_src="images/IronChef2.gif" width="192" height="256"><br/>
<img lazy_src="images/Cuppa.png" width="65" height="70"><br/>

Remember: We’re
trying to get the
browser to fetch
the visible page
content first!

jmaessen@google
Low-Quality Inline Images Above the Fold + Lazy Load
lazyload_images.html
<!doctype html>
<html><head>...</head>
<body>
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100"
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100"
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100"
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100"
<p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p>
<img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100"
<p>*</p> <p>*</p>
<p>Should be below the fold...</p>
<p>*</p> <p>*</p>
<script>...lazyload code...</script>
<img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/>
<img lazy_src="images/IronChef2.gif" width="192" height="256"><br/>
<img lazy_src="images/Cuppa.png" width="65" height="70"><br/>

height="100"><br/>
height="100"><br/>
height="100"><br/>
height="100"><br/>
height="100"><br/>

jmaessen@google
Effect of our Optimizations: Visual Completeness

Note: Mobile devices should
load all images by OnLoad to
avoid radio restart.

Before: 6.4s
With lazy load: 4.7s

jmaessen@google
Let PageSpeed Find Above the Fold Images
ModPagespeedEnableFilters lazyload_images,insert_image_dimensions
ModPagespeedEnableFilters resize_mobile_images

# Apache

pagespeed EnableFilters
pagespeed EnableFilters

# Nginx

lazyload_images,insert_image_dimensions;
resize_mobile_images;

Instrumented
Page

PageSpeed
Server

Clients vote on what
images are visible
above the fold

Beacon result:
List of visible images
Client
Browser

jmaessen@google
Lazy load your images
Use low-quality inline placeholder
images above the fold
Load all images before radio off
jmaessen@google
A Note About JavaScript
Page Reflows due to JavaScript are a problem
Statically sizing dynamically loaded areas eliminates page jank
Consider loading JS that affects the page earlier
But use asynchronous techniques (eg async ads load)

jmaessen@google
Ideal Page Load Order
Critical CSS (inlined)
Above the fold HTML with inline image previews
Below the fold HTML with image dimensions
Above the fold images
Below the fold images
Non-critical CSS
In parallel
JavaScript*
jmaessen@google
What This Looks Like on a Real Site

jmaessen@google
What This Looks Like on a Real Site
4.4s:
Unopt first render

1.8-1.9s:
First Render
2.2s:
Low Res Banner
2.4s:
Full Res Banner
3.7s:
Dynamic Image
http://www.radiocity.com/tickets.html

jmaessen@google
Inline critical CSS in <head>
Inline low res visible images
Lazy load everything else
jmaessen@google
Thank you!
Slides @

email
mod_pagespeed
nginx_pagespeed
PageSpeed Service

jmaessen@google.com
http://www.modpagespeed.com
http://ngxpagespeed.com
https://developers.google.com/speed/pagespeed/service

Contenu connexe

Tendances

Web Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessWeb Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessAustin Gil
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website AssetsChris Love
 
Building fast aspnet websites
Building fast aspnet websitesBuilding fast aspnet websites
Building fast aspnet websitesMaarten Louage
 
Responsive content
Responsive contentResponsive content
Responsive contenthonzie
 
Front-End Performance Optimizing
Front-End Performance OptimizingFront-End Performance Optimizing
Front-End Performance OptimizingMichael Pehl
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchTaylor Lovett
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website OptimizationGerard Sychay
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Timothy Fisher
 
Living on the Edge: Elevating your SEO toolkit to the CDN
Living on the Edge: Elevating your SEO toolkit to the CDNLiving on the Edge: Elevating your SEO toolkit to the CDN
Living on the Edge: Elevating your SEO toolkit to the CDNNils De Moor
 
Minimize website page loading time – 20+ advanced SEO tips
Minimize website page loading time – 20+ advanced SEO tipsMinimize website page loading time – 20+ advanced SEO tips
Minimize website page loading time – 20+ advanced SEO tipsCgColors
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYExtreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYMaximiliano Firtman
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupJonathan Klein
 
Build Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićBuild Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićMeetMagentoNY2014
 
Adobe CQ5 for Developers - Introduction
Adobe CQ5 for Developers - IntroductionAdobe CQ5 for Developers - Introduction
Adobe CQ5 for Developers - IntroductionTekno Point
 
Adobe AEM CQ5 - Developer Introduction
Adobe AEM CQ5 - Developer IntroductionAdobe AEM CQ5 - Developer Introduction
Adobe AEM CQ5 - Developer IntroductionYash Mody
 

Tendances (20)

Web performance
Web performanceWeb performance
Web performance
 
Web Performance: 3 Stages to Success
Web Performance: 3 Stages to SuccessWeb Performance: 3 Stages to Success
Web Performance: 3 Stages to Success
 
Lazy load Website Assets
Lazy load Website AssetsLazy load Website Assets
Lazy load Website Assets
 
Building fast aspnet websites
Building fast aspnet websitesBuilding fast aspnet websites
Building fast aspnet websites
 
Responsive content
Responsive contentResponsive content
Responsive content
 
Please dont touch-3.6-jsday
Please dont touch-3.6-jsdayPlease dont touch-3.6-jsday
Please dont touch-3.6-jsday
 
Front-End Performance Optimizing
Front-End Performance OptimizingFront-End Performance Optimizing
Front-End Performance Optimizing
 
Modernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with ElasticsearchModernizing WordPress Search with Elasticsearch
Modernizing WordPress Search with Elasticsearch
 
Keep the Web Fast
Keep the Web FastKeep the Web Fast
Keep the Web Fast
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Living on the Edge: Elevating your SEO toolkit to the CDN
Living on the Edge: Elevating your SEO toolkit to the CDNLiving on the Edge: Elevating your SEO toolkit to the CDN
Living on the Edge: Elevating your SEO toolkit to the CDN
 
Minimize website page loading time – 20+ advanced SEO tips
Minimize website page loading time – 20+ advanced SEO tipsMinimize website page loading time – 20+ advanced SEO tips
Minimize website page loading time – 20+ advanced SEO tips
 
Speed!
Speed!Speed!
Speed!
 
Novajs
NovajsNovajs
Novajs
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NYExtreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NY
 
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP MeetupWeb Performance, Scalability, and Testing Techniques - Boston PHP Meetup
Web Performance, Scalability, and Testing Techniques - Boston PHP Meetup
 
Build Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje JurišićBuild Better Responsive websites. Hrvoje Jurišić
Build Better Responsive websites. Hrvoje Jurišić
 
Adobe CQ5 for Developers - Introduction
Adobe CQ5 for Developers - IntroductionAdobe CQ5 for Developers - Introduction
Adobe CQ5 for Developers - Introduction
 
Adobe AEM CQ5 - Developer Introduction
Adobe AEM CQ5 - Developer IntroductionAdobe AEM CQ5 - Developer Introduction
Adobe AEM CQ5 - Developer Introduction
 

En vedette

Getting your PPE Facts Right - 5 Facts and 5 Myths
Getting your PPE Facts Right - 5 Facts and 5 MythsGetting your PPE Facts Right - 5 Facts and 5 Myths
Getting your PPE Facts Right - 5 Facts and 5 MythsKristy Thornton
 
What is the rol of product owner
What is the rol of product ownerWhat is the rol of product owner
What is the rol of product ownerMario Lucero
 
Must-Win Battles & Strategy of Discount Airline case study of Southwest Airlines
Must-Win Battles & Strategy of Discount Airline case study of Southwest AirlinesMust-Win Battles & Strategy of Discount Airline case study of Southwest Airlines
Must-Win Battles & Strategy of Discount Airline case study of Southwest AirlinesJukka Ala-Mutka, Dr Sc.
 
5 things you didn't know nginx could do velocity
5 things you didn't know nginx could do   velocity5 things you didn't know nginx could do   velocity
5 things you didn't know nginx could do velocitysarahnovotny
 
9 Things For Healthcare Marketing Sucess
9 Things For Healthcare Marketing Sucess9 Things For Healthcare Marketing Sucess
9 Things For Healthcare Marketing Sucessjohnluginbill
 
Directing ppt
Directing pptDirecting ppt
Directing pptSrv Saboo
 
Directing - Management
Directing - ManagementDirecting - Management
Directing - ManagementSanchit
 

En vedette (7)

Getting your PPE Facts Right - 5 Facts and 5 Myths
Getting your PPE Facts Right - 5 Facts and 5 MythsGetting your PPE Facts Right - 5 Facts and 5 Myths
Getting your PPE Facts Right - 5 Facts and 5 Myths
 
What is the rol of product owner
What is the rol of product ownerWhat is the rol of product owner
What is the rol of product owner
 
Must-Win Battles & Strategy of Discount Airline case study of Southwest Airlines
Must-Win Battles & Strategy of Discount Airline case study of Southwest AirlinesMust-Win Battles & Strategy of Discount Airline case study of Southwest Airlines
Must-Win Battles & Strategy of Discount Airline case study of Southwest Airlines
 
5 things you didn't know nginx could do velocity
5 things you didn't know nginx could do   velocity5 things you didn't know nginx could do   velocity
5 things you didn't know nginx could do velocity
 
9 Things For Healthcare Marketing Sucess
9 Things For Healthcare Marketing Sucess9 Things For Healthcare Marketing Sucess
9 Things For Healthcare Marketing Sucess
 
Directing ppt
Directing pptDirecting ppt
Directing ppt
 
Directing - Management
Directing - ManagementDirecting - Management
Directing - Management
 

Similaire à Prioritize your critical css and images to render your site fast velocity nyc 2013

Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
Odoo - Create themes for website
Odoo - Create themes for websiteOdoo - Create themes for website
Odoo - Create themes for websiteOdoo
 
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015beyond tellerrand
 
Diazo: Bridging Designers and Programmers
Diazo: Bridging Designers and ProgrammersDiazo: Bridging Designers and Programmers
Diazo: Bridging Designers and ProgrammersTsungWei Hu
 
HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010alanburke
 
LIS3353 SP12 Week 4
LIS3353 SP12 Week 4LIS3353 SP12 Week 4
LIS3353 SP12 Week 4Amanda Case
 
HTML & CSS - Le Wagon Bootcamp
HTML & CSS - Le Wagon BootcampHTML & CSS - Le Wagon Bootcamp
HTML & CSS - Le Wagon BootcampPaal Ringstad
 
HTML5 - An Introduction
HTML5 - An IntroductionHTML5 - An Introduction
HTML5 - An IntroductionTimmy Kokke
 
Moz SEO Web cheat sheet 2016
Moz SEO Web cheat sheet 2016Moz SEO Web cheat sheet 2016
Moz SEO Web cheat sheet 2016Nirav Patel
 
The Web Developer's SEO Cheat Sheet
The Web Developer's SEO Cheat Sheet The Web Developer's SEO Cheat Sheet
The Web Developer's SEO Cheat Sheet Shubham Kumar Singh
 
Seo cheat sheet
Seo cheat sheetSeo cheat sheet
Seo cheat sheetRohan Jha
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)christopherfross
 
Css week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourCss week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 

Similaire à Prioritize your critical css and images to render your site fast velocity nyc 2013 (20)

Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
Odoo - Create themes for website
Odoo - Create themes for websiteOdoo - Create themes for website
Odoo - Create themes for website
 
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
Scott Jehl - Delivering Responsibly - beyond tellerrand Düsseldorf 2015
 
Diazo: Bridging Designers and Programmers
Diazo: Bridging Designers and ProgrammersDiazo: Bridging Designers and Programmers
Diazo: Bridging Designers and Programmers
 
HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010HTML 5 Drupalcamp Ireland Dublin 2010
HTML 5 Drupalcamp Ireland Dublin 2010
 
LIS3353 SP12 Week 4
LIS3353 SP12 Week 4LIS3353 SP12 Week 4
LIS3353 SP12 Week 4
 
HTML & CSS - Le Wagon Bootcamp
HTML & CSS - Le Wagon BootcampHTML & CSS - Le Wagon Bootcamp
HTML & CSS - Le Wagon Bootcamp
 
HTML5 - An Introduction
HTML5 - An IntroductionHTML5 - An Introduction
HTML5 - An Introduction
 
Seo Cheat Sheet
Seo Cheat SheetSeo Cheat Sheet
Seo Cheat Sheet
 
Seo cheat-sheet
Seo cheat-sheetSeo cheat-sheet
Seo cheat-sheet
 
Moz SEO Web cheat sheet 2016
Moz SEO Web cheat sheet 2016Moz SEO Web cheat sheet 2016
Moz SEO Web cheat sheet 2016
 
Seo cheat-sheet
Seo cheat-sheetSeo cheat-sheet
Seo cheat-sheet
 
The Web Developer's SEO Cheat Sheet
The Web Developer's SEO Cheat Sheet The Web Developer's SEO Cheat Sheet
The Web Developer's SEO Cheat Sheet
 
Seo cheat sheet
Seo cheat sheetSeo cheat sheet
Seo cheat sheet
 
Seo cheat sheet
Seo cheat sheetSeo cheat sheet
Seo cheat sheet
 
Seo cheat-sheet
Seo cheat-sheetSeo cheat-sheet
Seo cheat-sheet
 
Seo onpage for Developer
Seo onpage for DeveloperSeo onpage for Developer
Seo onpage for Developer
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)
 
Css week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandourCss week10 2019 2020 for g10 by eng.osama ghandour
Css week10 2019 2020 for g10 by eng.osama ghandour
 
Web technologies part-2
Web technologies part-2Web technologies part-2
Web technologies part-2
 

Dernier

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Prioritize your critical css and images to render your site fast velocity nyc 2013

  • 1. Prioritize Your Critical CSS and Images WebRTCfast to render your site Jan-Willem Maessen PageSpeed Optimization Library Google jmaessen@google.com
  • 2. Prioritizing Critical CSS and Images Makes Render Fast jmaessen@google
  • 3. Inline critical CSS in <head> Inline low res visible images Lazy load everything else jmaessen@google
  • 4. Users Expect Speed Delay User reaction 0 - 100 ms Instant 100 - 300 ms Slight perceptible delay 300 - 1000 ms Task focus, perceptible delay 1 s+ Mental context switch 10 s+ I'll come back later... Our pages should render in 1000 ms or less Website Abandonment (Strangeloop) Ilya Grigorik (Go to his talk)
  • 6. Mobile web performance is crippled by network latency We need to build fast pages for today’s devices jmaessen@google
  • 7. Network Performance Varies Even in the Lab jmaessen@google
  • 8. Optimistic But Useful Model of HTTP Connection What is Happening Time Total data (200 ms RTT) (KB) Control plane (200-2500 ms) – DNS lookup 200 ms – TCP Connection 400 ms – First 10 packets (15K) 600 ms 14K Next 20 packets (29K) 800 ms Next 40 packets (44K) 1000 ms If your site is reached via a mobile redirect, you’re already down here. Time Total data (200 ms RTT) (KB) TCP DNS lookup Connection 800 ms – 44K First 10 packets (15K) TCP Connection 1000 ms 14K – 88K First 10 (15K) Next 20 packets (29K) 1200 ms 44K 14K 40 (44K) Next 20 packets (29K) 1400 ms 88K 44K Next 40 packets (44K) 1600 ms 88K Actually, all these numbers exceed the 384Kbit/s (48K/s) bandwidth of old 3G networks. Resource request (original host) (second jmaessen@google
  • 9. We don't need to render the entire page... We need to render above the fold content! 1. One RTT render for above the fold! 2. No redirects + fast server response (<200 ms) 3. Must optimize critical rendering path a. Inline critical CSS b. Remove blocking JavaScript c. Prioritize above-the-fold images @igrigorik
  • 10. Why can’t the browser do this? What CSS will affect the above the fold HTML? What HTML will be above the fold after styling? How large is each above the fold image? Will JavaScript affect the content of the DOM? jmaessen@google
  • 11. Step 1: Prioritize Your Critical CSS jmaessen@google
  • 12. Let's look at that simple example... prioritize_critical_css.html styles/blue.css <!doctype html> <html> <head> <title>prioritize_critical_css example</title> <link rel="stylesheet" href="styles/blue.css"> <link rel="stylesheet" href="styles/big.css"> <style> @import url(styles/all_using_imports.css); </style> <link rel="stylesheet" href=" styles/rewrite_css_images.css"> </head> <body> <div class="foo" style="display:inline-block;"></div> <span class="blue big">Prioritize Critical CSS</span> …<body> .blue {color: blue;} styles/big.css .big { font-size: 8em; } .very_large_class… { font-size: 8em; } …(lots more unused rules) styles/all_using_imports.css @import url(yellow.css); @import url(blue.css); @import url(bold.css); styles/rewrite_css_images.css .foo { background-image: url(../images/BikeCrashIcn.png); width: 100px; height: 100px; } jmaessen@google
  • 13. What happens when the browser loads our page prioritize_critical_css.html styles/blue.css <!doctype html> <html> <head> <title>prioritize_critical_css example</title> <link rel="stylesheet" href="styles/blue.css"> <link rel="stylesheet" href="styles/big.css"> <style> @import url(styles/all_using_imports.css); </style> <link rel="stylesheet" href=" styles/rewrite_css_images.css"> </head> <body> <div class="foo" style="display:inline-block;"></div> <span class="blue big">Prioritize Critical CSS</span> …<body> styles/big.css styles/all_using_imports.css @import url(yellow.css); @import url(blue.css); @import url(bold.css); styles/rewrite_css_images.css .foo { background-image: First render: url(../images/BikeCrashIcn.png); width: 100px; height: 100px; } 1.8s jmaessen@google
  • 14. Inline the CSS that is actually used on the page prioritize_critical_css.html <!doctype html> <html> <head> <title>prioritize_critical_css example</title> <style>.blue{color:blue}</style> <style>.big{font-size:8em}</style> <style>.blue{color:blue}.bold{font-weight:bold}</style> <style>.foo{background-image:url(images/BikeCrashIcn.png); width:100px;height:100px}</style> </head> First render: <body> <div class="foo" style="display:inline-block;"></div> <span class="blue big">Prioritize Critical CSS</span> …<body> 0.7s jmaessen@google
  • 15. Simplest Option: Just Inline All the CSS ● Around 40% of the CSS rules are used in a typical page ● Tweaking a PHP script to inline all the CSS should be easy ● Warning: 44K of compressed CSS on typical page As always, test and measure – do what the data tells you for your site. HTTP Archive data on CSS sizes jmaessen@google
  • 16. Identify critical CSS via an Audit (Manual) DevTools > Audits > Web Page Performance Inline the critical styles... @igrigorik
  • 17. Let PageSpeed Find Critical CSS Automatically ModPagespeedEnableFilters prioritize_critical_css # Apache pagespeed EnableFilters # Nginx prioritize_critical_css; Instrumented Page PageSpeed Server Beacon result: List of critical selectors Client Browser Downside: first access to the page won’t be optimized. Upside: will be based on actual client browser behavior jmaessen@google
  • 18. Rules That Are Triggered by JavaScript Actions Option 1: Include them in your critical CSS ● Careful: they may not necessarily show up in an audit! Option 2: Lazyload them ● Load before we run the relevant JavaScript ● Lazyload also works for non-screen styles (eg print) jmaessen@google
  • 19. How Not to Lazy Load CSS prioritize_critical_css.html <!doctype html> <html> <head> <title>prioritize_critical_css example</title> … </head> <body> <div class="foo" style="display:inline-block;"></div> <span class="blue big">Prioritize Critical CSS</span> … <link <link <link <link rel="stylesheet" rel="stylesheet" rel="stylesheet" rel="stylesheet" href="styles/blue.css"> href="styles/big.css"> href="styles/all_using_imports.css"> href="styles/rewrite_css_images.css" media="all"> The browser will notice the stylesheets when it reaches the bottom of the page and block rendering – It can’t tell that none of the rules will apply to the page. </body> </html> jmaessen@google
  • 20. How PageSpeed Optimization Library Lazy Loads CSS prioritize_critical_css.html <!doctype html> <html> <head> <title>prioritize_critical_css example</title> … </head> <body> <div class="foo" style="display:inline-block;"></div> <span class="blue big">Prioritize Critical CSS</span> … <noscript class="psa_add_styles"> <link rel="stylesheet" href="styles/blue.css"> <link rel="stylesheet" href="styles/big.css"> <link rel="stylesheet" href="styles/all_using_imports.css"> <link rel="stylesheet" href="styles/rewrite_css_images.css" media="all"> </noscript> <script>...Move <noscript> to a div...</script> </body> </html> The noscript block keeps the browser from downloading the CSS until the script runs. This blocks rendering when JS is switched off But the page continues to work correctly You can skip this for non-screen media= attributes. jmaessen@google
  • 21. Step 2: Lazy Load Below the Fold Images jmaessen@google
  • 22. Another very simple example... lazyload_images.html <!doctype html> <html><head>...</head> <body> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png"><br/> <p>*</p> <p>*</p> <p>Should be below the fold...</p> <p>*</p> <p>*</p> <img src="images/Puzzle.jpg"><br/> <img src="images/IronChef2.gif"><br/> <img src="images/Cuppa.png"><br/> </body> </html> images/BikeCrashIcn.png images/Puzzle.jpg images/IronChef2.gif images/Cuppa.png jmaessen@google
  • 23. Lazyloading All the Images lazyload_images.html <!doctype html> <html><head>...</head> <body> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <script>...lazyload code...</script> <img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>Should be below the fold...</p> <p>*</p> <p>*</p> <img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/> <img lazy_src="images/IronChef2.gif" width="192" height="256"><br/> <img lazy_src="images/Cuppa.png" width="65" height="70"><br/> jmaessen@google
  • 24. Include Dimensions with Lazy Loaded Images Without image dimensions (left), page reflows on image load jmaessen@google
  • 25. Don’t Lazy Load Images Above the Fold! lazyload_images.html <!doctype html> <html><head>...</head> <body> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img src="images/BikeCrashIcn.png" width="100" height="100"><br/> <p>*</p> <p>*</p> <p>Should be below the fold...</p> <p>*</p> <p>*</p> <script>...lazyload code...</script> <img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/> <img lazy_src="images/IronChef2.gif" width="192" height="256"><br/> <img lazy_src="images/Cuppa.png" width="65" height="70"><br/> Remember: We’re trying to get the browser to fetch the visible page content first! jmaessen@google
  • 26. Low-Quality Inline Images Above the Fold + Lazy Load lazyload_images.html <!doctype html> <html><head>...</head> <body> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100" <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100" <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100" <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100" <p>*</p> <p>*</p> <p>*</p> <p>*</p> <p>*</p> <img lazy_src="images/BikeCrashIcn.png" src="data:image/jpg;..." width="100" <p>*</p> <p>*</p> <p>Should be below the fold...</p> <p>*</p> <p>*</p> <script>...lazyload code...</script> <img lazy_src="images/Puzzle.jpg" width="1023" height="766"><br/> <img lazy_src="images/IronChef2.gif" width="192" height="256"><br/> <img lazy_src="images/Cuppa.png" width="65" height="70"><br/> height="100"><br/> height="100"><br/> height="100"><br/> height="100"><br/> height="100"><br/> jmaessen@google
  • 27. Effect of our Optimizations: Visual Completeness Note: Mobile devices should load all images by OnLoad to avoid radio restart. Before: 6.4s With lazy load: 4.7s jmaessen@google
  • 28. Let PageSpeed Find Above the Fold Images ModPagespeedEnableFilters lazyload_images,insert_image_dimensions ModPagespeedEnableFilters resize_mobile_images # Apache pagespeed EnableFilters pagespeed EnableFilters # Nginx lazyload_images,insert_image_dimensions; resize_mobile_images; Instrumented Page PageSpeed Server Clients vote on what images are visible above the fold Beacon result: List of visible images Client Browser jmaessen@google
  • 29. Lazy load your images Use low-quality inline placeholder images above the fold Load all images before radio off jmaessen@google
  • 30. A Note About JavaScript Page Reflows due to JavaScript are a problem Statically sizing dynamically loaded areas eliminates page jank Consider loading JS that affects the page earlier But use asynchronous techniques (eg async ads load) jmaessen@google
  • 31. Ideal Page Load Order Critical CSS (inlined) Above the fold HTML with inline image previews Below the fold HTML with image dimensions Above the fold images Below the fold images Non-critical CSS In parallel JavaScript* jmaessen@google
  • 32. What This Looks Like on a Real Site jmaessen@google
  • 33. What This Looks Like on a Real Site 4.4s: Unopt first render 1.8-1.9s: First Render 2.2s: Low Res Banner 2.4s: Full Res Banner 3.7s: Dynamic Image http://www.radiocity.com/tickets.html jmaessen@google
  • 34. Inline critical CSS in <head> Inline low res visible images Lazy load everything else jmaessen@google
  • 35. Thank you! Slides @ email mod_pagespeed nginx_pagespeed PageSpeed Service jmaessen@google.com http://www.modpagespeed.com http://ngxpagespeed.com https://developers.google.com/speed/pagespeed/service