Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed-up a HTTP request

I need to get json data and I'm using urllib2:

request = urllib2.Request(url)
request.add_header('Accept-Encoding', 'gzip')
opener = urllib2.build_opener()
connection = opener.open(request)
data = connection.read()

but although the data aren't so big it is too slow.
Is there a way to speed it up? I can use 3rd party libraries too.

like image 623
rubik Avatar asked Sep 18 '25 19:09

rubik


1 Answers

Accept-Encoding:gzip means that the client is ready to gzip Encoded content if the Server is ready to send it first. The rest of the request goes down the sockets and to over your Operating Systems TCP/IP stack and then to physical layer.

If the Server supports ETags, then you can send a If-None-Match header to ensure that content has not changed and rely on the cache. An example is given here.

You cannot do much with clients only to improve your HTTP request speed.

like image 90
Senthil Kumaran Avatar answered Sep 21 '25 08:09

Senthil Kumaran