Improving performance of https request in backend

Hi all,

I’m making a super simple fetch request to an external api via https, but the fetch request takes forever to complete in the backend (1.8s from code vs. 0.3 seconds if I just paste the request URL into my Chrome search bar).

My Backend code is here:

/**
 * A function that gets a list of districts for filling dropdowns for a location
 * Inputs: 
 * - language: The user's preferred language
 * - state: The state of the location
 * Outputs:
 * - districts: a list of districts (values in English and labels in user language)
 */
export async function get_districts(language, state){
    
    // Define the url to call the website backend
    let url = 'https://mywebsite-gateway.dev/get_districts';
    url += "?key=" + await getSecret("mywebsite_backend_api_key");
    url += "&language=" + language;
    url += "&country=" + 'India';
    url += "&state=" + state;
    
    // Make the url call and return the result
    const districts = await getJSON(url)
        .catch((error) => {
            console.log('There was an error getting a location from the backend');
            console.log(error);
        });
    return districts; 
}

My frontend function call looks something like the following:

// Time the function start
var start = performance.now();

// Run the function
$w('#district').options = await get_districts('en','Massachusetts');

// Time the function end
var end = performance.now();        
console.log(end-start); // =1.8 seconds

Any ideas on how to improve the performance here? At 1.8 seconds I basically can’t host my website on Wix. Way too slow :-(.

Looks like this has gone over a year without reply. I’m actually in the same boat. It’s very frustrating, as soon as I publish my site, it seems to run at a reasonable speed, then just gets slower and slower over time. Makes it very difficult to understand what’s going on and I’ve spent forever just trying to get some simple webhooks to store data without taking forever or skipping information.