Yogesh Chauhan's Blog

How does AdSense calculate page loading time?

in JavaScript & Miscellaneous on February 17, 2021

When a user visits a page, the time it takes for the browser to render the page usable is recorded in the domInteractive event.

To calculate the mobile page loading time, Google uses the Navigation Timing API to get the domInteractive timings for a sample of the traffic coming to your pages with AdSense ads, then take the median of the samples.

What is Navigation Timing API?

The Navigation Timing API provides data that can be used to measure the performance of a web site.

Unlike JavaScript-based libraries that have historically been used to collect similar information, the Navigation Timing API can be much more accurate and reliable.

You can use the Navigation Timing API to gather performance data on the client side.

We can can then transmit that data to a server using XMLHttpRequest or other techniques.

Navigation Timing API lets you measure data that was previously difficult to obtain, such as
➛ the amount of time needed to unload the previous page,
➛ how long domain lookups take,
➛ the total time spent executing the window’s load handler and more.

window.performance property

The window.performance property returns a Performance object. The Navigation Timing API adds two properties to it: timing and navigation.

PerformanceNavigationTiming

It provides methods and properties to store and retrieve metrics regarding the browser’s document navigation events.

For example, this interface can be used to determine how much time it takes to load or unload a document.

Example


const perfData = window.performance.timing;
const pageLoadTime = perfData.loadEventEnd - perfData.navigationStart;

This subtracts the time at which navigation began (navigationStart) from the time at which the load event handler returns (loadEventEnd). This gives us the perceived page load time.

Sources

Google Support and MDN


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS? #Jan 8 How to Install Xcode Command Line Tools on MacOS?
You might also like these
HTML canvas methodsHTMLWordPress: How to find all posts with a specific custom field value?WordPressHow to Recognize an Array in JavaScript?JavaScriptFive common features of Angular template syntax (with examples)AngularFor In Loop in Swift for BeginnersSwiftLearn to make a responsive gallery using CSS Grid and without media queriesCSS