The Ultimate Guide to Website Performance Testing

2024년 1월 1일 오전 12:00|테크니컬 SEO|읽기 시간: 9분

The Ultimate Guide to Website Performance Testing: Combining Lighthouse + Window Performance to End "Mystical" Optimization

As website creators, we all want our sites to be enjoyable for users and favorable to search engines. Website performance is the foundation of it all. If a page takes forever to load, users will leave, and search engines won't look kindly upon it. This is especially true now that most people browse on mobile devices, where network speeds can be unstable. A slow website essentially means saying goodbye to traffic.

In the past, discussing performance optimization often felt like a "mystical" art, with no clear starting point. But now, we have excellent tools that help us quantify problems and pinpoint bottlenecks. Among them, Google Lighthouse and the browser's native Window Performance API are the two most common "Swiss Army knives."

This guide will explore how to master these two tools, moving you from "gut-feeling" optimization to data-driven improvements that genuinely enhance website performance and user experience.

Therefore, performance optimization is not an option; it's a necessity.

2. Lighthouse: The "Comprehensive Health Check" for Your Website

Google Lighthouse is like a "doctor" for your website, providing scores across multiple dimensions like performance, accessibility, best practices, SEO, and PWA (Progressive Web App). It generates a detailed report, showing you what you're doing well and where you need to improve.

How to Use Lighthouse?

It's incredibly simple, with three common methods:

  1. Chrome DevTools (F12): The most convenient and common way. Open the webpage you want to test, press F12 to open DevTools, find the "Lighthouse" tab (formerly "Audits"), select the categories you want to audit (e.g., Performance), choose the device (Mobile/Desktop), and click "Analyze page load." Chrome DevTools Lighthouse
  2. Lighthouse Chrome Extension: Install the Lighthouse extension from the Chrome Web Store and run a test with a single click on the icon.
  3. Node CLI (Command-Line Interface): Ideal for automated testing or integration into CI/CD pipelines. You'll need to install Node.js first, then install Lighthouse via npm (npm install -g lighthouse), and run it from the command line (lighthouse <url>).

What to Look for in a Lighthouse Report?

The report gives you scores (0-100) for several key dimensions; the higher, the better. We'll focus on the Performance score and its related metrics.

3. Interpreting Lighthouse Performance Metrics (No More Confusion)

The Lighthouse performance report is filled with colorful metrics and acronyms. Don't worry, let's break them down one by one:

Lighthouse Performance Metrics

  1. First Contentful Paint (FCP): This marks the time when the first piece of DOM content (e.g., text, image, SVG) is rendered on the page. In simple terms, it's the moment the user sees something other than a blank white screen. A shorter FCP time makes the page feel faster.
  2. Largest Contentful Paint (LCP): (A Core Web Vital) This measures the time it takes for the largest visible content element (usually an image, video, or a large block of text) to be rendered in the viewport. LCP is a crucial metric for perceived loading speed because it indicates when the main content of the page has likely loaded. Google recommends an LCP of under 2.5 seconds.
  3. Speed Index (SI): This metric shows how quickly the content of a page is visually populated during load. A lower SI score means the page content appears faster, making the experience feel smoother.
  4. Time to Interactive (TTI): This is the time it takes for a page to become fully interactive. "Fully interactive" means the page not only displays content but can also reliably respond to user input (like clicks or text input). A long TTI means users might see the page but can't interact with it, leading to a poor experience.
  5. Total Blocking Time (TBT): (Highly related to interactivity and a Core Web Vital) This measures the total time between FCP and TTI where the main thread was blocked by long tasks (any task taking more than 50ms). High TBT indicates that the page may feel sluggish or unresponsive to user actions during loading. Metrics that measure actual interaction delay, like First Input Delay (FID) or Interaction to Next Paint (INP), are often affected by TBT.
  6. Cumulative Layout Shift (CLS): (A Core Web Vital) This measures the total of all unexpected layout shifts that occur during the entire lifespan of the page. In simple terms, it's when elements on the page suddenly move around, like an image loading and pushing text down, or an ad suddenly appearing. A lower CLS score means better visual stability and a better user experience. Google recommends a CLS of less than 0.1.

How to Interpret These Metrics?

  • Look at the colors: The report typically uses green (good), orange (moderate), and red (poor) to color-code the metric scores, making them easy to understand at a glance.
  • Read the recommendations: Lighthouse not only gives scores but also provides specific optimization suggestions (Opportunities and Diagnostics), such as "Reduce unused JavaScript," "Optimize images," and "Enable text compression." These recommendations are extremely valuable and following them can significantly improve performance.

Real-World Tip: Don't just chase scores! Sometimes a high score doesn't reflect a good user experience (e.g., if the core functional area of the page loads slowly). Always analyze the report in the context of your business goals and user feedback.

4. Window Performance API: The "Microscope" for Performance Details

Lighthouse provides simulated test results from a lab environment. While comprehensive, it might not perfectly match the experience of real users. The browser's native Window Performance API, however, allows you to get more realistic, granular performance data, and even collect performance data from real users (Real User Monitoring, RUM).

What Can the Window Performance API Do?

It provides a set of interfaces that let you access detailed timing information for page loads and resource loading within your JavaScript code.

Common API Examples:

  1. performance.timing: (This API is being deprecated, but it's still used in a lot of legacy code and articles) It provides timestamps for various stages of the page load, such as navigationStart, fetchStart, domLoading, domInteractive, domContentLoadedEventEnd, and loadEventEnd. By calculating the differences between these timestamps, you can get various durations, like DNS lookup time, TCP connection time, white screen time, DOM ready time, and total page load time.
    1// Example: Calculate approximate First Paint Time 2let timing = performance.timing; 3let whiteScreenTime = timing.responseStart - timing.navigationStart; 4console.log('Approximate white screen time:', whiteScreenTime, 'ms');
  2. performance.navigation: Provides information about how the page was loaded (e.g., new navigation, refresh, back/forward) and the number of redirects.
  3. performance.getEntriesByType(entryType): This is extremely useful! It retrieves performance entries of a specific type.
    • performance.getEntriesByType('navigation'): Gets data from the Navigation Timing API (the recommended replacement for performance.timing).
    • performance.getEntriesByType('resource'): Gets detailed timing information for all resources loaded on the page (JS, CSS, images, Ajax requests, etc.), including URL, duration, and size. Analyzing this can help you find specific resources that are slowing down your site.
    • performance.getEntriesByType('paint'): Gets paint-related timings, like first-paint and first-contentful-paint.
    • performance.getEntriesByType('largest-contentful-paint'): Gets LCP data.
    • performance.getEntriesByType('layout-shift'): Gets CLS data.
    • performance.getEntriesByType('longtask'): Gets long task data (for analyzing TBT).
  4. performance.mark(markName) and performance.measure(measureName, startMark, endMark): These allow you to create custom timestamps and measure durations in your code. For instance, if you want to measure the time taken for a complex calculation or to render a specific module, you can create marks at the beginning and end and then use measure to calculate the difference.
    1performance.mark('startCalculation'); 2// ... perform some complex calculation ... 3performance.mark('endCalculation'); 4performance.measure('calculationTime', 'startCalculation', 'endCalculation'); 5let measures = performance.getEntriesByName('calculationTime'); 6console.log('Calculation time:', measures[0].duration, 'ms');

How to Make the Most of the Window Performance API?

  • Analyze in Context: Don't just look at generic metrics. Analyze the performance of your core business flows (e.g., product page loading, order submission).
  • Data Reporting and Monitoring (RUM): Report the real user performance data you collect via the API (like LCP, CLS, FID/INP, and custom measurements) to your monitoring platform (either self-built or a third-party RUM service). This allows you to continuously track production performance and identify widespread issues.

5. Lighthouse + Window Performance API: An Unbeatable Combination?

Lighthouse and the Window Performance API each have their pros and cons. Using them together is the key to unlocking their full potential:

  • Lighthouse (Lab Testing):
    • Pros: Comprehensive, standardized, provides detailed optimization suggestions, easy to use, great for quick diagnostics in development/testing environments.
    • Cons: Simulated environment may differ from real user experience; cannot fully replicate all network conditions and devices.
    • Use Cases: Developer self-testing, pre-launch checks, version comparisons, identifying common performance issues, getting initial optimization directions.
  • Window Performance API (Real User Monitoring - RUM):
    • Pros: Based on real user data, reflects actual experience; can collect more granular, long-term performance data; allows for custom measurement of critical business paths.
    • Cons: Requires developing a data collection and analysis system (or using a third-party RUM service); large data volume can be complex to analyze; does not directly provide optimization suggestions.
    • Use Cases: Monitoring live production performance, discovering issues not reproducible in lab environments, evaluating the impact of optimizations, long-term performance trend analysis, correlating performance with business metrics.

The Golden Workflow:

  1. Daily Development/Testing: Use Lighthouse for quick performance checks and initial optimizations based on its recommendations.
  2. Dedicated Performance Optimization: Use Lighthouse to identify major bottlenecks, then dive into the details of resource loading, long tasks, etc., using the Window Performance API.
  3. Production Monitoring: Use the Window Performance API to collect real user data (RUM) to continuously monitor core metrics and business flow performance, with alerts for any issues.
  4. Verifying Optimization Impact: After deploying optimizations, use Lighthouse to compare before-and-after results and monitor the trends in your RUM data.

6. Conclusion: End "Mystical" Practices, Drive Performance with Data

Website performance optimization is no longer a "mystical" practice based on gut feelings and guesswork. With powerful tools like Lighthouse and the Window Performance API, we can:

  • Quantify Performance: Turn vague notions of "fast" or "slow" into concrete metrics and data.
  • Pinpoint Bottlenecks: Quickly identify what's slowing down your website.
  • Guide Optimization: Get targeted recommendations to make your optimization efforts effective.
  • Validate Results: Use data to measure the impact of your optimizations and drive continuous improvement.

Remember, performance optimization is an ongoing process. The tools are just the means to an end—the ultimate goal is to enhance the user experience and earn the trust of both users and search engines.


One last question: What challenges have you faced while using Lighthouse or the Window Performance API? Or do you have any secret tips? Share them in the comments below!