Performance Monitoring
01/10/2024 02:45

3rd Party Script Performance Monitoring

Essential KPIs to Monitor the Impact of Third-Party Scripts on Website Performance

media

3rd Party Script Performance Monitoring

As websites and applications grow more complex, the use of third-party scripts—whether for analytics, ads, or other integrations—has become widespread. However, these external scripts can often become significant performance bottlenecks. Monitoring the performance of third-party scripts is critical to ensuring a smooth user experience. This article will highlight key performance metrics you should be tracking, such as CPU time, request time, request chains, script size, and the importance of CDN usage for third-party scripts.

CPU Time of Each Script

The amount of CPU time a third-party script consumes is one of the most critical performance indicators. CPU time reflects how long the browser spends executing the script, which can directly impact the responsiveness of your website. Scripts that take too long to execute can block the main thread, delaying user interactions and causing slow page loads.

Example:

performance.getEntriesByType('resource').forEach(script => {
  if (script.initiatorType === 'script') {
	console.log(`Script ${script.name} used ${script.duration}ms of CPU time`);
  }
});

Why it matters: Monitoring CPU time helps identify which scripts are placing the most load on the browser. Optimizing or replacing heavy scripts can significantly improve the responsiveness of your site.

Request Time

Request time refers to the total time taken to load a third-party script, from when the request is made to when the script is downloaded. While some scripts are cached, others must be reloaded every time, and longer request times can add noticeable delays to your website.

Example:

performance.getEntriesByType('resource').forEach(script => {
  if (script.initiatorType === 'script') {
	console.log(`Script ${script.name} took ${script.responseEnd - script.startTime}ms to load`);
  }
});

Why it matters: Understanding how long it takes to request and load third-party scripts can help you identify slow-performing resources and take corrective actions like caching or lazy loading.

Request Chain / Indicator

Third-party scripts often have dependencies or initiate other requests, creating what is known as a request chain. These chained requests can compound delays, especially if multiple scripts depend on each other. Understanding the request chain helps identify which scripts are causing bottlenecks and how you can optimize their order or defer loading unnecessary ones.

Example:

performance.getEntriesByType('resource').forEach(script => {
  console.log(`Script ${script.name} initiated ${script.nextHopProtocol} requests`);
});

Why it matters: By analyzing the request chain, you can break inefficient dependencies or sequence the loading of scripts more effectively. Minimizing request chains reduces the overall page load time, leading to a more efficient user experience.

Script Size – Compressed and Uncompressed

While most scripts are transferred in a compressed format, the uncompressed size still plays a crucial role. A large script may be transferred quickly over the network, but once it’s downloaded, the browser must parse and evaluate it. The larger the uncompressed size, the longer this parsing and evaluation process takes, which directly affects page performance.

Example:

const scriptSize = new Blob([scriptContent]).size;
console.log(`Uncompressed script size: ${scriptSize} bytes`);

Why it matters: Even with efficient compression, reducing the uncompressed size of third-party scripts is crucial to minimizing the time the browser spends processing JavaScript. Optimizing or eliminating unnecessary code in these scripts can significantly speed up page rendering.

3rd Party Script CDN Usage

Another crucial factor in third-party script performance is whether or not the script is served via a CDN (Content Delivery Network). CDNs distribute the script across multiple servers globally, reducing the physical distance between the user and the resource. This can drastically cut down on request times, especially for international users.

Example:

if (script.name.includes('cdn')) {
  console.log(`Script ${script.name} is served via CDN`);
} else {
  console.log(`Script ${script.name} is NOT served via CDN`);
}

Why it matters: Serving scripts from a CDN ensures that they are loaded quickly, regardless of the user’s location. If a third-party script isn’t using a CDN, you may want to consider alternative scripts that are better optimized for global performance.

Conclusion

Monitoring the performance of third-party scripts is essential for maintaining a fast, responsive website. Key metrics like CPU time, request time, request chains, script size, and CDN usage all provide valuable insights into how external scripts are affecting your site’s performance. By paying attention to these factors, you can optimize your site for speed and efficiency, reducing the impact of third-party scripts on your overall user experience.

Catch Metrics is the leading solution to help solve ad stack performance problems.Get in touchto learn more from our experts

Get Started Today

Sign up for a demo or contact our team to learn more about how Catch Metrics can help you achieve your goals. As part of all demos we offer a free Ad Speed Audit and ROI modelling exercise to help you understand how your Ad speed is impacting your revenues.