Is it possible to utilize the NavigationTimingAPI with asynchronous requests?

Currently, I am working on implementing performance measuring functionality in our project that utilizes custom elements v1.

The NavigationTimingAPI provides detailed measurements for various navigation types (navigate, reload, browser back/forward):

https://i.sstatic.net/Z3dj0.png

Is there a similarly detailed API available for measuring asynchronous calls? Or is there another API for this purpose that I am not aware of?

Specifically, when the page has fully loaded and user interaction triggers a POST or GET request to a server-based resource.

So far, the only method I found is setting measurement points using performance.mark().

Have I overlooked any essential information in this context?

Answer №1

When discussing performance metrics, you mentioned utilizing Navigation Timing, identifying User Timing with the use of performance.mark(), but overlooked the valuable Resource Timing API. All three components are integral parts of the overarching Performance Timing API.

Navigation Timing primarily focuses on measuring the loading time of a homepage or application, while the Resource Timing API offers insights into the loading process of individual asynchronously loaded resources in relation to navigation times.

Consider this: Asynchronously loaded files lack a DOM environment to execute! Consequently, resource timing lacks certain DOM properties. However, the starting point remains consistent with that of navigation timing:

https://i.sstatic.net/jvgzk.png

One key property within the Performance Timing API is startTime, which holds significant importance. Each asynchronous call possesses its own unique startTime, with a value of 0 for documents and >0 ms for JavaScript files and other resources.

The startTime serves as the initial timestamp, marking the commencement of resource loading by the browser. In resource timing, startTime aligns with either fetchStart or redirectStart (if not zero) when measuring a resource's timing.

Instances such as CSS or image resources lack both DOM interaction and execution capabilities. Whereas resources with a .js extension engage in JavaScript execution, allowing for user timing through performance.mark() actions, as previously noted.

  • Can the NavigationTimingAPI be used on asynchronous calls?

The answer lies somewhere between yes and no. Resource Timing automatically logs relevant marks that can be compared against Navigation Timing data, facilitating useful analyses. Although there is potential for utilizing NavigationTimingAPI on asynchronous calls, it should be noted that measuring the index.html (navigation) differs from tracking async calls (resources):
Simply switch from

performance.getEntriesByType("navigation")
to
performance.getEntriesByType("resource")
.

Answer №2

It seems I overlooked something obvious in this situation.

Every XMLHTTPRequest containing all relevant information is automatically transformed into a PerformanceResourceTiming object within

performance
  .getElementsByType("resource")
  .filter(function(x) { 
    return x.initiatorType === "xmlhttprequest";
  });

I mistakenly focused solely on the performance.timing object (the only thing not accessible through performance.getElementsByType()).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS bracket-enhanced template

Why is AngularJS giving an error when brackets are used inside ng-template content? I am trying to create an input field that should accept an array, but I keep getting this error message: "Error: Syntax Error: Token ']' not a primary expression ...

When a function is called, retrieve a specific number of elements from an array using the slice method in

If I have an array of 15 objects, but I am only displaying 5 on the browser using this code: const displayedArray = array.slice(0,4) I also have a function that will load another 5 objects each time a user scrolls down. displayedArray.concat(array.slice ...

Tips on triggering another action before a loop completes, involving AJAX

I've been struggling with this issue for quite some time now and I'm out of ideas. Can anyone offer assistance, please? All I want is to reload the current page after adding items to the cart. I've tried various methods like using count, pr ...

Click to add a card

Attempting to incorporate a new row with the click of a button dynamically has proven to be challenging for me. As someone who is relatively new to JavaScript, I am struggling to figure it out. In the demonstration provided below, you will notice that noth ...

Cypress, encountering issues with If/Else or Switch Case implementations

My current challenge involves adding else if / switch case in my test. The issue I am facing is that when the initial 'if' condition fails, it does not go into the else if statement. This problem persists in both else if statements and switch cas ...

Enhance your Vue.js application by dynamically adding a class when a computed value

Just delving into the world of vue.js and I have a simple query. I've been following a tutorial but now I'd like to add my own touch to it :-P Whenever there is a change in my rank, I would like to include a CSS class for animating the label. Ho ...

Is there a way to apply styles to a checkbox's child element depending on the checkbox's state without relying on ternary operators within Styled Components?

I am currently working on styling this component using Styled Components, but I feel like my current approach is a bit of a hack. What would be the best practice for incorporating Styled Components to style this component effectively? If I were to use Pla ...

Monitor modifications to a DOM element's ClientRect dimensions

I have developed a component that utilizes the context feature to register a DOM node and include it in a QuadTree. export default class SelectableGroup extends React.PureComponent { getChildContext() { return { register: this.register, ...

Error Alert: Invalid type specified in React.createElement - Electron-React-Boilerplate

As a designer looking to expand my skills into coding for personal projects, I decided to start with the navigation UI in the [electron-react-boilerplate][1] that I cloned. However, I encountered the following error message: Error Warning: React.createEle ...

Iterate through the classes for updates rather than focusing on individual id fields

I am currently working on creating a function that can refresh data with an AJAX call for multiple instances of a class within a single page. The function functions perfectly when there is only one instance on the page: $(document).ready(function() { ...

What is the most effective way to import and load three-orbitcontrols?

Has anyone tried implementing the OrbitControls function in conjunction with ReactJS? I have included a snippet of the code below: import React, { Component } from 'react'; import 'tachyons'; import * as THREE from 'react'; im ...

Using JSON objects effectively in MVC4, including parsing them seamlessly!

I am struggling with understanding how to effectively utilize JSON objects within MVC and the correct way to pass them from Controller, to View, to Jscript. I am also unsure if I am correctly parsing the JSON objects at the appropriate places... Within m ...

When dragging and dropping in react-flow-renderer, make sure to duplicate the node

I am working on implementing a feature where the original node remains in its position while allowing drag and drop functionality to create a new node at the drop location. The original node should stay at its initial position. When dragging a duplicate n ...

Variables defined within a React useEffect are not accessible outside of the function

I'm facing a scope issue where I need to declare a constant variable inside the useEffect hook in React, but the variable is not recognized outside the function. import React, { useEffect } from "react"; function Commentsbox(props) { useEffect(( ...

Leveraging Vuex stores in a modular WebPack setup

I am currently working on a web application where each page of the site has 2 JS files: a global "bootstrap.js" file that is consistent across every page and a custom JS file specific to each page. I've run into an issue where I want these files to sh ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...

Warning on React component listing due to key issue originating from the parent component

Alert: It is essential that each child in a list has a distinct "key" prop. Please review the render method of ForwardRef(ListItem). A child from RecipientsList was passed. I have located this issue using the react-components debugger tool on Chrome. I ad ...

What's causing these divs to be misaligned in various directions?

I am currently working with a front-end framework based on flexbox called Material-UI, and I have noticed that the layout of certain components, particularly the quantity control elements, appears to be different even though they all share the same styling ...

Verify the length of an array within an object using JavaScript

I am facing a problem with an object. Here is what it looks like: const array = { "entities": [ { "annexes": [ { "buildingUniqueIds": [] }, { ...

Stopping the webdriver in Node.js gracefully without crashing it can be achieved through a

Can the selenium webdriver be halted without terminating node? I've encountered a problem attempting to create an API tool that conducts web automation upon receiving a get request. Essentially, I am executing the selenium webdriver on a get request ...