Picture from Simon Howden freedigitalphotos.net!
hacking web
performance
maximiliano firtman
@firt
firt.mobi
Picture from Simon Howden freedigitalphotos.net!
hacking web
performance
maximiliano firtman
@firt
firt.mobi
9
Picture from Simon Howden freedigitalphotos.net!
hacking web
performance
m9o firtman
@firt
firt.mobi
Picture from Simon Howden freedigitalphotos.net!
hacking web
performance
max firtman
@firt
firt.mobi
mobile+web developer & trainer
trainer
SOON
I have 2 goals…
Make you feel bad
Show you new tricks
😁
Let’s Start!
I know you know
http://www.flickr.com/photos/steenslag/22689920/ - borrowed fromSteve Souders
Picture from Simon Howden freedigitalphotos.net
18
Picture from Simon Howden freedigitalphotos.net
It's mostly frontend responsibility!
User-centric metrics



User-centric metrics

First Meaningful Paint 

User-centric metrics

First Interactive 

User-centric metrics

Speed index 

Goals

First Meaningful Paint: 1-3s
First Interactive: 2-4s
Speed Index: 2-3s
You are already…
Optimizing the network transfer


You are already
Working with TLS and HTTP/2


You are already
CSS as Appetizer


You are already
JavaScript as Dessert


You are already
Optimizing Images


You are already
Defining an HTTP Cache Policy


You are already
Using Service Workers


You are already
You are already doing this
What’s the problem then?
First Contentful Paint


The problem
HTTP Archive with Lighthouse
Time to Interactive


The problem
HTTP Archive with Lighthouse
2 3 4
5 6 7 8
8.9
1
Average time to load a mobile landing page


The problem
22 seconds
Research by thinkwithgoogle.com
If a page takes more than 3 seconds to load


The problem
53% leave it
Research by Double Click
The problem
We always
underestimate
mobile
iOS and Android
Safari and Chrome?
browsers with market share
Using Cellular Networks!
We have 4G! We don't need to
worry about performance...
(
)
www.gsma.com/mobileeconomy - Dec 2018
www.gsma.com/mobileeconomy - Dec 2018
~10% of the time 4G is not used
Bandwidth
cellular networks
RTT - latency
cellular networks
Min Max
RTT - latency
cellular networks
Min Max
We still have a big performance
problem on the Mobile Web
(
)
Chrome Lite Pages 🆕
Chrome 73 Android
Chrome Lite Pages
• If users enables Data Saver
⭐🆕
Lite Page will be rendered if
Chrome Lite Pages
• You are in a 2G network

OR
• First Contentful Paint greater than 5s
⭐🆕
Lite Page?
Chrome Lite Pages
• Cloud-based rendering
• "Smart" Optimizations
• Not all images loaded
⭐🆕
Try it!
Chrome Lite Pages ⭐🆕
Progressive Web Apps 🆕
Progressive Web Apps 🆕
Progressive Web Apps 🆕
Progressive Web Apps 🆕
Progressive Web Apps 🆕
Let’s hack Web Performance!
Hack First Load
Avoid more than one roundtrip
First Load
• TCP Slow Start - initial congestion window 

(initcwnd)
• Linux: 14.6 KiB
KiB?
🤔
How many bytes in a kilobyte?
1 KB = 1024 bytes
1 KB = 1024 bytes
1 KB = 1000 bytes
1 KiB = 1024 bytes
Avoid more than one roundtrip
First Load
• TCP Slow Start - initial congestion window 

(initcwnd)
• Linux: 14.6 KiB
Above the Fold
(ATF)
Below the Fold
(BTF)
Deliver ATF in 14.6 KiB
First Load
• Embed all CSS and JavaScript needed
• If space, embed logo and/or low-res images
Avoid http to httpS redirect
First Load
• Use HSTS (HTTP Strict Transport Security)
• Header
• Opt-in at hstspreload.org
Hack Data Transfer
QUIC over HTTP
Data Transfer
• Experimental transport protocol over UDP
• Reduces latency and connection messages
• HTTP/2 Interface with TLS
•
Data Transfer
Image from Chromium Blog
Data Transfer
• Google: +3%
• YouTube: -30% buffering
• Facebook similar protocol: +2%
• 75% of requests can be optimized
QUIC
Data Transfer
It's currently the draft of HTTP/3!
Use Zopfli
Data Transfer
• Save 3-8% data transfer with GZIP
• It’s ~80x slower
Use Brotli
Data Transfer
• Save ~25% data transfer compared with GZIP
• Check Encoding Header
Use Brotli
Data Transfer
• LinkedIn: 4% savings in load time
• Facebook: 17% savings on CSS, 20% on JavaScript
Hack Resource Loading
Modern Cache Control
Resource Loading
• Hash in filenames is common for versioning
• Browsers make conditional requests
Modern Cache Control
Resource Loading
• Hello to Cache-Control: immutable
Modern Cache Control
Resource Loading
It’s a common new pattern to
• 1) serve from the cache
• 2) update it in the background for later
Modern Cache Control
Resource Loading
Cache-Control: stale-while-revalidate=99
Warming up engines
Resource Loading
• Help the browser to start processes ASAP
• DNS Queries: ~200ms
• TCP and TLS connection: ~200ms
Announce DNS queries ASAP


<link rel="dns-prefetch" href=“https://newdomain.com">
HTML
Resource Loading
Announce TLS connections ASAP


<link rel="preconnect" href=“https://newdomain.com”
crossorigin>
HTML
Resource Loading
Announce on HTTP Response


Link: <https://my-analytics.com>; rel=preconnect;
crossorigin
HTTP
Resource Loading
Preloading
Resource Loading
Help the browser prioritize resources for rendering
Preloading
Resource Loading


<link rel="preload" href=“styles.css” as=“style”>
HTML
Preloading
Resource Loading


Link: <https://otherhost.com/font.woff2>; rel=preload;
as=font; crossorigin
HTTP
Priority Hints
Resource Loading


<link rel="preload" as="image" 

href="hero.jpg" importance="high">
<img src="otherimage.jpg" importance="low">
HTML
🆕
To bundle or not to bundle
Resource Loading
• On HTTP/2 might seem an anti-pattern
• But it’s not!
Resource Loading
To bundle or not to bundle
Resource Loading
• Bundle!
• But not everything
• First, code-splitting and load only the important
Web Fonts
Resource Loading
• Avoid FOUT (Flash of Unstyled Text)
• font-display: optional or swap
Resource Loading
Hack Images
http://www.flickr.com/photos/steenslag/22689920/ - borrowed fromSteve Souders
A picture is worth a thousand
words…
… if it loads
Preloading Responsive Images
<link rel="preload" as="image" 

imagesrcset="200w.jpg 200w, 300w.jpg 300w" 

imagesizes="(max-width: 500px) 50vw, 650px">
HTML
🆕
Images
Lazy Image Loading
<img src="photo.png" alt="Never forget it"
loading="lazy">
HTML
🆕
Images
Source: addyosmani.com
Time to replace standard
JPEG and PNG
Images
Lossless format: Zopfli PNG
https://github.com/imagemin/zopflipng-bin
20%
Images
Lossless format: Guetzli JPEG
https://github.com/google/guetzli
20-30%
Images
Hack User Experience
Meet HTTP Client Hints
Images
• Browser will expose data to the server


<meta http-equiv="Accept-CH"
content="DPR, Viewport-Width, Device-Memory”>
HTML
Meet HTTP Client Hints
Images
•Today we can ask for
• RTT
• Downlink
• ECT (2g, 3g, 4g, slow-2g)
• Save-Data
• DPR and Viewport-Width
• Device-Memory
Reactive Web Performance
User Experience
Know about context with APIs
User Experience
• Network Information
• Performance Observers
• Save-Data Client Hint
• Device Memory Client Hint
Consistent Experience
User Experience
• Web Fonts
• Change SW’s cache policy
• SSR vs CSR
• Reduce amount of loaded data
• 1x image not matter DPR
Get Reports from the Browser
User Experience
• Reporting API
• Report-To header with a server endpoint
• Browser will send you reports about problems,
including Chrome Lite Pages activation
First Load
Data Transfer
Resource Loading
Images
User Experience
Hack
Why Performance
Performance is TOP PRIORITY
Push it even more
It’s a worthwhile effort
Feeling bad enough?
Foto de freefoto.com
www.firt.mobi
@firt
FREE!

Hacking Web Performance 2019