Right now, I am sending out 3 GET requests for JSON files using Axios. I wonder if they are being loaded simultaneously or one after the other

In the process of developing my application, I am loading 3 JSON files to gather information about a game's characters, spells, and more. As of now, I have implemented 3 functions that utilize axios to make GET requests and store the responses. However, Iam uncertain if this approach is causing a delay in load time because I am not sure if these JSON files are loaded simultaneously or sequentially. Each file takes around 45 ms to load, so if they are being loaded sequentially, the total load time could be approximately 135 ms which is not optimal.

I have experimented with 2 different approaches but have not noticed any significant difference in loading time when checking Chrome's network tab. For reference, these functions reside in my Vue.js Vuex store, and the calls are triggered within the App.vue mounted hook.

The first method involves three separate functions, each making an individual GET request and then calling one after another:

this.$store.dispatch('getChampions')
this.$store.dispatch('getSummonerSpells')
this.$store.dispatch('getSummonerRunes')

The functions are defined as follows:

getChampions({commit, state}){
    //axios code for getting champions
},
getSummonerSpells({commit, state}){
    //axios code for getting summoner spells
},
getSummonerRunes({commit, state}){
    //axios code for getting summoner runes
}

Alternatively, the second method involves a single function calling all three requests at once:

this.$store.dispatch('getRequirements')

The function is structured like this:

getRequirements({commit, state}){
    axios.all([
        //axios GET requests for all 3 JSON files
    ])
    .then(axios.spread((response1, response2, response3) => {
        commit('champions', {
            champions: response1.data.data
        })
        commit('summonerSpells', {
            summonerSpells: response2.data.data
        })
        commit('summonerRunes', {
            summonerRunes: response3.data
        })
    }))
}

Answer №1

When you run the requests in parallel, your browser will try to execute them at the same time. The decision on whether it actually does this is ultimately up to the browser itself.

To monitor what's happening, you can utilize your browser's Network console timing column (known as Waterfall in Chrome).

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

If you're wondering if there's a difference between these requests, the answer is "no" in terms of timing.

If you encounter errors with a specific request, using your first option is more reliable since axios.all will reject the promise if any fail.


To improve speed, consider developing a service that combines the three results into one before sending a single request. Additionally, implementing a cache like Varnish can provide an extra boost in performance.

Answer №2

Upon completion of all requests, a sequence of response objects will be delivered to you in the exact sequence in which they were submitted. The `Commit()` function is invoked only after both of your requests have finished processing.

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

Initially, when fetching data in React, it may return as 'undefined'

I have a function component in React that handles user login. The functionality is such that, based on the username and password entered by the user in the input fields, if the API response is true, it redirects to another page; otherwise, it remains on th ...

Enhance your Next JS website's SEO with a combination of static pages, SSR pages, and client-side

In my project using Apollo GraphQL with Next JS, I have explored three different approaches to querying and rendering data. The first method involves Static Rendering by utilizing getStaticProps(), which looks like the following: export async function getS ...

"Process the contents of a file by reading it line by line in a

Currently, I am reviewing the documentation for the nodejs readline module in order to tackle a task that involves reading a very large file line by line. The solution using readline seems promising, although I require it to read lines synchronously - mean ...

Troubleshooting Vue 3: Issues with retrieving input field values

Vue 3 has been a bit challenging for me to grasp, especially related to making axios calls and handling input field values. In my Vue installation folder, I am trying to retrieve input values from the form fields to implement a login function which at lea ...

Challenges with Knockout.js Virtual Elements in Different Environments

I am facing a peculiar issue where a virtual knockout template fails to bind correctly when accessed remotely, yet functions perfectly when viewed locally. You can find the problematic page here: Here is the template I am using: <ul> <!-- k ...

Retrieving the caret's position in TinyMCE 4

Is there a way to retrieve the caret position in pixels (x & y dimensions) in TinyMCE 4 without obtaining row/column numbers? It should be relative to anything and achieved without adding any extra tags like bookmarks. Anyone know if TinyMCE has a method f ...

Acquire dynamically loaded HTML content using Ajax within a WebView on an Android

I have been attempting to extract the content of a web page on an Android platform. Despite trying JSoup, I faced a limitation with ajax support. As an alternative, I am endeavoring to embed the URL within a hidden web view and retrieve the HTML in the on ...

Data within AngularJS is bound when receiving an Ajax response in HTML

In my current project, I am using Python/Django for the backend with a complex structure of forms. The frontend consists of an Angular controller that makes requests to fetch a suitable form. While working on this, I came across a Django-Angular package th ...

Visualize data from ajax call in tabular format

I want to display the results of an SQL query in a table using AJAX. I have written code that executes the query during the AJAX call, but when I try to display these values in a table, it shows null values on the div tag. What could be the reason for this ...

Having difficulty launching a new window within an app built with Electron and Nexjs (Nextron)

Attempting to launch a (Nextjs-generated) page in a new window is causing an error message to appear: Uncaught ReferenceError: global is not defined Here is the full error: react-refresh.js?ts=1665849319975:10 Uncaught ReferenceError: global is not de ...

Analyzing DynamoDB Query

I am on a mission to recursively analyze a DynamoDB request made using the dynamo.getItem method. However, it seems that I am unable to locate a similar method in the DynamoDB SDK for Node.js. You can find more information about DynamoDB SDK at http://do ...

A guide on accessing the first element in an array when performing multiplication within the Interval component in React.js

I am having trouble initiating an if statement from number 0 once the window is loaded, as it seems to be skipping over 0 and starting from 1 instead. Can someone please assist me in understanding how this works? showAnime = () => { let counter ...

Show the Canvas element at the back of the DIV

This particular question requires a clear explanation. My goal is to have the canvas act as a background element on the page, while the main content of the page starts in its usual position. I attempted using separate DIVs with their own Z-index values, bu ...

Steps to invoke a function in a PHP file from an external JavaScript file

Can anyone assist me with calling the function below in my PHP file? function update_hidden_input(saved_tokens, hidden_input) { var token_values = $.map(saved_tokens, function (el) { //alert(el[settings.tokenValue]); return el[ ...

Uncover the secrets of HTML with JavaScript

I'm facing an issue with extracting data from a link's data attribute and trying to decode the HTML within it, but unfortunately, it's not functioning as expected. Check out my code on JSFiddle: http://jsfiddle.net/Kd25m/1/ Here's the ...

Why does json_encode() work for one string and fail for another?

UPDATE: Resolved the issue. Initially, someone left a comment with a solution that was later deleted. Interestingly, simply adding semi-colons after the two json_encode lines fixed the problem. I'm still puzzled as to why string1 worked without a clo ...

Tips for toggling an Electron.js submenu within a Vue.js Component based on a particular Vuex state

I've searched everywhere for a solution to this issue. Currently, I am working on a sample vue-vuex-electron app that I have developed. My goal is to dynamically enable or disable certain submenus within the app based on the vuex state 'isLogged ...

What are the best practices for utilizing "async/await" and "promises" in Node.js to achieve synchronous execution?

I'm fairly new to the world of web development and still grappling with concepts like promises and async/await. Currently, I'm working on a project to create a job posting site, but I've hit a roadblock trying to get a specific piece of code ...

What is the best way to prevent double clicks when using an external onClick function and an internal Link simultaneously

Encountering an issue with nextjs 13, let me explain the situation: Within a card component, there is an external div containing an internal link to navigate to a single product page. Using onClick on the external div enables it to gain focus (necessary f ...

What is the process for reinserting a list item into the nested elements?

Looking for help with manipulating a menu in HTML? I have a menu that I want to modify by removing and adding list items. While I've had success removing items, I'm struggling to properly use the add method. Here's an example of what my menu ...