Track the loading time of a webpage and the time it takes to render all subelements of

For my project, I need to track page load times for each individual visitor. My idea is to embed a JavaScript snippet into the page in order to achieve this goal. However, the task is more complex than I anticipated because I also need to measure the response times for all subrequests made during the page load process, including those sent to third-party systems like CDNs or Google. Moreover, there are numerous AJAX calls that occur throughout the page loading sequence, and I must ensure that only requests made before the completion of the initial page load event are recorded. Once all measurements have been captured, they need to be transmitted back to the server for storage using XMLHttpRequest. Has anyone encountered a similar challenge in the past? Are there any recommendations or sample scripts available?

Thank you.

Answer №1

UPDATE: Although a good start, the issue remains that certain content is loaded asynchronously. Determining the loading time for images, for example, presents a challenge. However, it can be applied in AJAX calls.

One approach to address this is provided here: http://jsfiddle.net/45Lpwhyv/

function LoadingTimer() {
    this.timestamp = null;
    this.parts = [];
}

LoadingTimer.prototype.start = function (data) {
    this.stop();
    var i = this.parts.length;
    this.parts[i] = {};
    this.parts[i].data = data;
    this.timestamp = new Date().getTime();;
};

LoadingTimer.prototype.stop = function () {
    if (this.timestamp !== null) {
        this.parts[this.parts.length - 1].duration = (new Date().getTime()) - this.timestamp;
        this.timestamp = null;
    }
};

This class enables passing a data parameter to the timer, such as a string indicating the current section of the document being loaded. To utilize it, instantiate LoadingTimer and call .start("sectionName") for each action requiring tracking. To pause a section without starting another immediately, simply invoke .stop.

lt = new LoadingTimer();
lt.start("Time before first dialog closes.");
alert("Loading time will be recorded upon closing this dialog.");
lt.start("Time before second dialog closes.");
alert("Let's move on to the next!");
lt.stop();

Additional methods could be implemented to eventually transmit the data to the server, potentially using JSON format.

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

Issue when Updating Component State: React child cannot be an object

I'm currently in the process of familiarizing myself with React and how to manage component state. My goal is to build a component, set up the initial state using a constructor, make a GET request to the server to fetch an array of objects, and then ...

What is the best way to reference an i18n entry within .json files?

I am in the process of creating a user interface using SAP UI5 and my goal is to make all text elements internationalized. Below is a snippet of my view in .xml format where I successfully retrieve text in different languages using placeholders enclosed i ...

Reverse the color of H1 text within a vertical div

Is it feasible to reverse the coloring of a segment within an h1 element using a div, horizontally? Refer to the illustration shown in the image below. https://i.sstatic.net/QAKwD.jpg ...

Press the button to access the URL within the current window

Working with Angular, I attempted to develop a function to open a URL in the current window. However, the code below within the controller actually opens a new window: $scope.openUrl = function(url) { $window.open(url); }; ...when using ng-click=&apo ...

Tips for displaying a div briefly before loading the second page

Incorporating a div named ADD, I aim to successfully load a second page within the current one using ajaxload. The challenge lies in displaying a div for 4 seconds before loading the second page. How can this be achieved? Following the wait period, the sec ...

The values of variables persist even after refreshing the page

let quote; let author; // Establishing the Get Method for the Root Route in ExpressJS app.get('/', (req, res)=>{ res.render('home', { quote: quote, writer: author }); }); // Configuring the Post Method for t ...

Is it possible to cache silverlight WCF service calls?

The service being called by the application is using WCF BinaryEncoding and requires 3 parameters. While I have experience with making similar calls using JavaScript Ajax stacks, I have not attempted it with Silverlight before. I am wondering if this is p ...

Run a Javascript function when the expected event fails to happen

I currently have this setup: <input type="text" name="field1" onblur="numericField(this);" /> However, I am struggling to figure out how to execute the numericField() function for the element before the form is submitted. I attempted using document ...

Sending JSON objects via AJAX to an ASP.NET callback page and serializing them

My webpage is built using asp.net and is fully ajaxified with the jquery library. I am encountering an issue where some users are experiencing an error when trying to serialize a JSON object. The error message reads: "There was an error deserializing the ...

What is the best way to incorporate Vuetify into a new application?

Recently, I developed a new app using Vue and I decided to integrate Vuetify as the framework. After executing the npm install vuetify --save command, Vuetify was added to the app successfully. However, when I tried to use it, the CSS button colors were no ...

The attribute 'subtle' is not found within the definition of 'webcrypto' type

Currently, I am working with Node v17.4 and I am looking to utilize the webcrypto API. Referencing this specific example, I am attempting to include subtle in my project, but TypeScript is throwing an error: Property 'subtle' does not exist on ...

Exploring the mechanics behind ES6 Map shims

From what I've gathered from the documentation (here and here), it seems that having a reference to the memory address is necessary for the operation to work: const foo = {}; const map = new Map(); map.set(foo,'123'); // This action requi ...

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...

Tablesorter with FilteredPages for enhanced server-side filtering

Currently, I am facing a dilemma regarding updating the filteredPages value in tablesorter when implementing server-side filtering. In my setup with version 2.13.2, I have successfully configured custom output that is accessible through p.ajaxData. This a ...

What is the best way to update the value of a specific key in discord.js?

As I struggle to explain properly due to my limited English proficiency, I am reiterating my question. In my config.json file, there is a key named "status" with a corresponding value of "online". I am attempting to change this value but haven't been ...

Ways to remove an automatically inserted underscore along with a timestamp

I'm currently tackling a project utilizing MVC5 and I've encountered an issue with MVC's interference. I'm trying to organize views by separating their JavaScript without modifying the bundle configuration. Although adjusting generic l ...

Find the string "s" within a div element aligned vertically, using Popper

Currently utilizing Popper from Material-UI <Popper id={"simplePopper"} open={true} style={{backgroundColor: 'red',opacity:'0.5',width:'100%',height:'100%'}}> <div style={{height:"100%", ...

performing asynchronous operations with async functions within the array.map() method in JavaScript

My goal is to loop through an array of elements, check if a theme exists for each element using the "findOne()" function, and if not, create a new theme, save it, and make some changes. If the theme already exists, I just need to apply some changes and the ...

Which event in the listbox should I trigger to adjust the scroll position?

My webpage includes a listbox inside an update panel. I've managed to capture the scroll position, but now I'm facing difficulty in identifying the right javascript event to call my function for setting the scroll position after the update panel ...

Tips for refreshing extensive JSON structures?

I receive product data from the server in JSON format, containing properties and nested arrays up to 4 levels deep. In the frontend, users can update values within these nested structures. Should I keep track of the path and reconstruct the entire JSON obj ...