Web Performance Fundamentals
Introduction
Part 1: Understanding
Part 2: Improving
Part 3: Planning
Elements of Performance
Why Care About Web Performance
Part 1: Understanding
- Psychology of performance
- Measuring performance
- Interpreting performance data Why is performance important?
You can see lot of charts that try to explain how is performance improvement improve the business but correction != causation
Why is performance important #1
- Google says so
- Google will rank you on your performance
Why is performance important #2
- Angry and frustrated users don’t stick around long
Perceived Performance
Analysis
- What behavior on the website slowed down your experience?
- How might the business model of each site contribute to their site’s performance?
Psychology of Waiting
Wait time feels subjective
- People want to start
- Board waits feel slower
- Anxious waits feel slower
- Unexplained waits feel slower
- Uncertain waits feel slower
- People will wait for value
Web Vitals
Measuring Web Performance
The Old Way: Page load
- Gaming the metrics – Lazy loading
The New Way: Web vitals
- Start -> FCP -> LCP -> CLS
- FID(First Input Delay)
First Contentful Paint(FCP)
- The time until the user sees an indication that the page is loading
Largest Contentful Paint(LCP)
- The time until the user sees most of the page and believes it is (almost) ready
Cumulative Layout Shift(CLS)
- The movement distance and impact of page elements during the entire lifetime of the document the user sees
How might this impact Client-Side Rendering?
First Input Delay(FID)
- The browser time delay between the user’s first click and execution of application code
FCP -> Respond quick
LCP -> Get to the point
CLS -> Don’t move stuff
FID -> Don’t load too much
Loading
- LCP
- Good < 2.5s < Needs improve < 4.0s < Poor
Interactivity
- FID
- Good < 100ms < Needs improve < 300ms < Poor
Visual Stability
- CLS
- Good < 0.1 < Needs improve < 0.25 < Poor
Lighthouse
Chrome lighthouse quirks and gotchas
- Relative to your machine, network
- Chrome window size
- Chrome application priority
Metrics
Where to Measure Performance
Where do we measure from?
- Server -> User(Usually we just use local dev environment to test not user environment)
- Synthetic Data(Use a test server to measure performance)
- Field Data(Sent user data to a monitoring server ps.RUM tools like requestmetrrics.com)
Chrome User Experience
Signal to noise
- Signal: Lab data < Synth Data < Field Data
- Noise: Lab data < Synth Data < Field Data
Interpreting Field Data
If we got 95 lighthouse score in lab data, we may got serval field data score like 98/96/86…
- Understanding the sample
- Averages
- Median and percentiles
- May be we should most care about the P95 user’s experience
Improving Performance
Web Business Objectives
Part 2: Improving
- Business objectives
- Improving each web vital
- Code demos and exercises
Web Business Objectives(Where the money comes from)
- Awareness
- Retention
- Conversion
- Competition
For short time durations, the difference must be at least 20% for most people to care.
Performance API
Performance API - Entry Timings
performance.getEntries()
performance.getEntriesByType()
performance.getEntriesByName()
Prompt for unload | redirect | App cache | DNS | TCP | Request | Response | Processing | Onload |
---|---|---|---|---|---|---|---|---|
navigationStart | redirectStart/redirectEnd | fetchStart | domainLookupStart/domainLookupEnd | connectStart/(secureConnectionStart)/connectEnd | requestStart | responseStart/responseEnd | domLoading/domInteractive/domContentLoaded/domComplete | loadEventStart/loadEventEnd |
Performance API - Performance Observer
1 | new PerformanceObserver((entryList) => { |
Performance Analytics
1 | (function (ready) { |
Performance Analytics Conclusions
- CLS is inversely correlated to Session Time
- LCP is inversely correlated to Bounce Rate
Note: this is only for some site, not a universal rule
Optimizing Metrics
How to improve performance?
- Do fewer things!
Improving FCP
First contentful paint
- The time until the user sees an indication that the page is loading.
- Response quick
Requirement
- Quick server
- Small files
- short transport
Server side:
- Sized correctly
- Minimal processing
- Network bandwidth
Small documents:
- Content size
- Compression
Short transmission
- Use CDNs(USA East coast to West coast is 200-300ms)
Improving LCP
Largest contentful paint
- The time until the user sees most of the page and believe it is(almost) ready
- Get to the point
Methods:
- Defer resources until later
- Optimize images
- Reduce request overhead
1 | <!-- use async attribute will still block the render --> |
- Safari and ie doesn’t support loading attribute!
1 | /** |
Responsive Images
1 | <img |
Also, we can use tinyPNG or other tools to crunch images
1 | const path = require('path'); |
HTTP2, Catching, and Pre-Loading
Reduce overhead with HTTP/2
Pros | Cons |
---|---|
Faster | Server setup + Compatibility |
Reuse connections | SSL Required |
Reduce overhead with caching
1 | cache-control: max-age=600 |
Reduce overhead with preloading
1 | <link rel="preconnect" href="https://fonts.gstatic.com" /> |
Improving CLS
Cumulative layout shift
- The movement distance and impact of page elements during the entire lifetime of the document the user sees.
- Don’t move stuff
Before vs. after LCP
- Layout hints
Demonstration: Banner positioning
Improving FID
First Input Delay
The browser time delay between the user’s first click and execution of application code
Don’t load too much
We got this issue because we moving deckchairs
But will users wait for that?
- How anxious are they?
- How valuable is it to them?
- Do they understand the wait?
Data Beyond Spreadsheets
After above optimizations, did we improve performance?
Business projections
- Improving session time
- Improving bounce rates
Data beyond spreadsheets
- Flame distribution
- Web vitals
- Time breakdown
Planing
- Performance culture
- Working with non-tech folks
- Designing new applications
Performance Panel
Performance Culture
Performance is a team value
- It’s not a task
- Performance is like security and quality has to do cross the entire circle
- Test performance early
- Test performance often
- Monitor performance always
- You need data
- Fast is part of planning
Goals & Performance Budget
Setting your goals
- Who are your users?
- What device(s) do they have?
- How long will they wait?
- How fast would impress?
Performance Scenarios
Scenario: Marketing wants to add another third-party pixel service
- You need data
- Not a performance chart
- Maybe you need a bounce and session time chart
- You definitely need a revenue and checkout chart
- Without data, you might be wrong
Scenario: Designing a new web app
- Business objective
- Import metrics