Answer the question
In order to leave comments, you need to log in
Fetch slows down when requesting the same url again. Why?
This function sends requests to the server in my React Native app. If the request comes for the first time, the difference between start and end is minimal, and if the request goes the second and then again to the same url, or the url differs in parameters from the request that has already been, the delay is from 15 to 30 seconds approximately. In Postman, all requests go quickly. With what it can be connected?
async function request(url, method = 'GET', data, contentType = 'application/json') {
const state = store.getState()
const config = {
method,
headers: {
'Accept': 'application/json',
'Authorization': state.user.token
}
}
if (contentType === 'application/json') config.headers['Content-Type'] = 'application/json'
if (method === 'POST' || method === 'PATCH') {
config.body = data
}
console.log('start', url, new Date())
const response = await fetch(url, config)
console.log('end', url, new Date())
return await response.json()
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question