http icon indicating copy to clipboard operation
http copied to clipboard

[iOS] Slow request on first connection "for each new endpoints"

Open delfme opened this issue 2 years ago • 0 comments

Hello, We noticed that first http request is pretty slow due to connection delay and subsequent request are fast.

Inside app we call same server on different endpoints and the slow request occurs every time a new endpoint is called first time. This impairs experience coz with our current implementation a slow response tends to occur frequently. I see we could use Client (like code below) but it is not meant to be kept open throughout entire app session.

var client = http.Client();
try {
  var response = await client.post(
      Uri.https('example.com', 'whatsit/create'),
      body: {'name': 'doodle', 'color': 'blue'});
  var decodedResponse = jsonDecode(utf8.decode(response.bodyBytes)) as Map;
  var uri = Uri.parse(decodedResponse['uri'] as String);
  print(await client.get(uri));
} finally {
  client.close();
}

Is there a way to workaround/avoid this issue by just better coding it?

delfme avatar Jun 15 '23 18:06 delfme