Picture from Simon Howden freedigitalphotos.net!
hacking web
performance
Maximiliano Firtman
@firt
firt.mobi
mobile+web developer & trainer
😬
trainer
I have 2 goals…
Show you new tricks
😁
Make you feel bad
Let’s Start!
I know you know
http://www.flickr.com/photos/steenslag/22689920/ - borrowed fromSteve Souders
Picture from Simon Howden freedigitalphotos.net
16
Picture from Simon Howden freedigitalphotos.net
500ms delay, +26% user’s frustration
Source: Radware
:(
500ms delay, -20% Google’s traffic
1 http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt
:(
+100ms delay, -1% Amazon’s sales
1 http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt
:(
User-centric metrics

First Meaningful Paint 

User-centric metrics

First Interactive 

User-centric metrics

Visually Complete 

User-centric metrics

Custom Metric 

I know you know
Performance is important
We need goals to achieve
Goals

First Meaningful Paint: 1-3s
First Interactive: 2-4s
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
Avoiding Redirects


You are already
You are already doing this
What’s the problem then?
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 thinkwithgoogle.com
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
2G
3G
4G
Home
0 250 500 750 1000
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
⭐🆕
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 (10 segments)
• CDNs are playing with different values
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 (aka HTTP/3)
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’s search page: 3% improvement
• YouTube: reduced 30% buffering
• Facebook similar protocol: 2% improvement
• 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
Readable Streams
Data Transfer
• Process data as it arrives in chunks
• 45% savings on paint metrics 

(when data is client-side rendered)
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
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
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" importante="high">
<img src="otherimage.jpg" importance="low">
HTML
🆕
Hack Images
http://www.flickr.com/photos/steenslag/22689920/ - borrowed fromSteve Souders
A picture is worth a thousand
words…
… if it loads
Embrace Responsive Images
Data Transfer
• Not just 3 versions of your image
• 65% of the traffic is for images (HttpArchive)
• 84% improvement creating n versions (ScientiaMobile)
Preloading Responsive Images
Resource Loading
<link rel="preload" as="image" 

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

imagesizes="(max-width: 500px) 50vw, 650px">
HTML
🆕
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
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
Decode images in a thread
Images
• github.com/GoogleChrome/offthread-image
Reactive Web Performance
User Experience
Know about the context
User Experience
• Client-side Performance APIs
• Network Information API
• Device Memory Client Hint
• Save-Data Client Hint
Hack User Experience
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
Consistent Experience
User Experience
• Web Fonts
• Change SW’s cache policy
• SSR vs CSR
• Reduce amount of loaded data
• 1x image not matter DPR
Feeling bad enough?
Performance is TOP PRIORITY
Push it even more
It’s a worthwhile effort
Foto de freefoto.com
www.firt.mobi
@firt
See you tomorrow 9am
Say hi to AR on the Web

Hacking Web Performance