http
http copied to clipboard
[iOS] Slow request on first connection "for each new endpoints"
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?