AI summary by TwinMind
Hacking LightHouse Scores
Theo - t3․gg
44m 2s
Lighthouse Score Importance and Limitations
- Product managers push for high Lighthouse scores, marketing/sales teams claim importance for web success
- Developers use scores to evaluate frameworks, often used to shame Angular apps
- Key question: Do these scores actually mean anything? Can they be hacked?
- Sponsored content by Sentry, article by Salma on "How to hack your Google Lighthouse scores in 2024"
Field Data vs Lab Data Critical Distinction
- Local performance testing on high-spec dev machines ($4,000 MacBook) not realistic for user experience
- Lab data provides directional trends but doesn't paint full picture of reality
- Field data from real users on various devices, connection speeds, browsers more accurate
- Application performance monitoring tools like Sentry provide real-world user data
- Philip Walton 2021 report: Almost 50% of pages scoring 100 on Lighthouse didn't meet core web vital thresholds based on HTTP archive data
Web Performance Beyond Speed Metrics
- Google 2018 report: Bounce probability increases 32% if page load time exceeds 3 seconds, 123% at 10 seconds
- Page load not single moment in time - multiple moments affect user perception
- Speed influenced by business KPIs and sales targets
- Physical limitations: humans and servers spread globally, infrastructure can only deliver limited bytes
- Example: Ping.gg gets "super fast" user feedback but poor Lighthouse scores due to homepage video player
- Mobile score: 44 performance
- Desktop score: 95 performance
- Site intentionally blocks mobile users and Firefox users (WebRTC bugs)
Lighthouse Performance Score Calculation
- Weighted combination of core web vitals and speed metrics:
- Total Blocking Time (TBT): 30%
- Cumulative Layout Shift (CLS): 25%
- Largest Contentful Paint (LCP): 25%
- First Contentful Paint (FCP): 10%
- Speed Index (SI): 10%
Total Blocking Time (TBT) Analysis
- Measures time after FCP when main thread blocked preventing user input responses
- Main thread considered blocked when JS task runs >50ms
- Ensures page responds to physical user input (key presses, mouse clicks, touch, typing)
- Frameworks like Qwik built specifically to solve this problem
Cumulative Layout Shift (CLS) Details
- Measures unexpected visual shifts after content shown to user
- React docs example: Logo switching based on localStorage causes complex implementation to prevent layout shift
- Required blocking main render, checking localStorage, swapping before page display
- Good CLS score: <0.1, poor score: >0.25
Largest Contentful Paint (LCP) Specifications
- Marks when page's main content likely loaded and useful
- Good LCP score: <2.5 seconds (higher threshold than expected)
- Elements considered for LCP:
- Image elements
- Image elements inside SVG
- Video elements (major issue for Ping.gg)
- Elements with background images (URL function, not CSS gradients)
- Block-level elements with text nodes
- Excluded elements: zero opacity, full viewport coverage, placeholder/low entropy images
First Contentful Paint (FCP) and Speed Index (SI)
- FCP: First point where users see something on screen
- SI: Measures how quickly content visually displays during page load
- Good FCP score: <1.8 seconds
- Good SI score: <3.4 seconds
- Demonstrates importance of loading states vs blank pages during server-side generation
- Example: Next.js loading.tsx files provide immediate feedback vs waiting for server response
Lighthouse Scoring Methodology
- Uses log-normal distribution derived from real website performance data (HTTP archive)
- Site scored against real web performance data, not in isolation
- Non-linear relationship: substantial improvements to low scores easier than improving high scores
- Usability favored over raw speed in scoring algorithm
LCP Hacking Techniques
- Show minimal LCP-qualifying content on load, delay real content until after Lighthouse test
- Demo: Page with single H1 element, real content loads after 10 seconds
- Lighthouse awards perfect 100 score even with single punctuation mark as LCP element
- Approach works with arbitrary splash screens containing minimal viable LCP elements
- Not recommended: terrible for SEO (robots can't discover main content), poor user experience
- Rent Path 2021 case study: Improved Lighthouse score 17 points by increasing thumbnail image sizes
- Made thumbnails larger than Google map tiles to control LCP element selection
- Literally making page slower improved LCP score by controlling largest element
CLS Hacking Methods
- Defer layout shifts until after page load event completion
- Demo page: 0.143 CLS score despite immediate JS adding text elements
- 5-second setTimeout delay results in perfect 0 CLS score with confetti celebration
- CSS animations using transform don't trigger CLS (unlike DOM manipulation)
- Hack won't work for field data or long-term user experience
- Time span tests in Lighthouse correctly report non-green CLS (~0.16)
Speed Index - Unhackable Metric
- Based on visual progress during page load timeline
- No way to fake loading content faster than actual speed
- Only optimization: load as much content as early as possible
- Recommendations for improvement:
- Deliver static HTML from CDN
- Avoid/minimize images
- Optimize image formats (Next.js image component example)
- Serves WebP/AVIF based on browser capability vs original PNG/JPEG uploads
- Minimize/eliminate CSS
- Prevent JavaScript/external dependencies loading during test window
Total Blocking Time (TBT) Hacking
- Measures main thread blocking after FCP preventing user input responses
- Good TBT score: <200ms
- JS-heavy SPAs prone to poor TBT scores
- Example: Twitch.tv terrible scores due to client-side page generation
- Mobile: Very poor performance
- Desktop: Still poor due to extensive client-side processing
- Possible hack: Defer all JavaScript until after Lighthouse test completion
- Modern frameworks/hosting providers reducing TBT issues through better server-side processing
Lighthouse Limitations Demonstration
- 2019 Manuel experiment: Terrible page scoring well in Lighthouse still works in 2024
- Demo page: Input events disabled by CSS/JS for 5 seconds
- Page technically unresponsive but scores 100 for performance and accessibility
- Lighthouse can't detect every usability/accessibility issue
- Cannot substitute for actual usability testing and common sense
Additional Hacking Strategies
- Use fastest, highest-spec hardware for testing
- Ensure fastest internet connection possible
- Never use field data, only lab data with optimal conditions
- Rerun tests with different conditions until desired results achieved
- Potentially serve different page versions to testing IP addresses
Performance Monitoring Recommendations
- Think of Lighthouse as "canary in coal mine"
- Use application monitoring tools like Sentry for real production data
- Focus on actual user experience over artificial scores
- Field data more important than lab scores for business outcomes
