The power of window.performance

Simuratli
3 min readDec 6, 2023

--

An object of this type can be obtained by calling window.performance or self.performance in workers.

One powerful tool that developers can leverage to measure and optimize performance is the window.performance API. In this blog post, we'll dive into the details of this API, exploring its key metrics, real-world use cases, and practical tips for improving web performance.

Overview of window.performance

window.performance API provides a set of tools for developers to measure various aspects of a website’s performance. It gives insights into crucial metrics that help in understanding how quickly a web page loads and renders.

Main properties:

performance.toJSON()

Returns a JSON representation of the Performance object.

Performance.eventCounts

An EventCounts map containing the number of events that have been dispatched per event type.

performance.now()

For high-resolution timestamps, developers can turn to performance.now(). This function is useful for measuring time intervals within the application.

performance.getEntries()

The getEntries() method returns an array of all PerformanceEntry objects currently present in the performance timeline.

performance.timeOrigin

The timeOrigin read-only property of the Performance interface returns the high-resolution timestamp that is used as the baseline for performance-related timestamps.

Real-world Use Cases

Developers can harness the power of window.performance in practical scenarios, such as:

  • Measuring Page Load Times: Use performance.timing to assess how quickly a page loads and identify areas for improvement.
  • Identifying Rendering Bottlenecks: Analyze timestamps to pinpoint bottlenecks in the rendering process and enhance the user experience.
  • Analyzing Network Performance: Leverage metrics to gain insights into network-related issues, optimizing the loading of external resources.

Improving Performance

To make the most of window.performance for performance optimization, consider these tips:

  • Analyze and Interpret Metrics: Understand the meaning of each metric to draw meaningful conclusions about the performance of your web page.
  • Identify Areas for Optimization: Pinpoint areas that need improvement by examining the timestamps provided by the API.
  • Implement Changes Based on Insights: Use the insights gained from window.performance to implement changes that enhance overall performance.

--

--

Simuratli

MSc. High Energy and Plasma Physics | B.A. Computer Engineering | Content Creator