Is there any difference in performance when using different HTTP methods?

I know how HTTP methods work and what they are intended for, but I'm curious to know if some methods are faster than others when used only to retrieve data.
In the team I'm working on, I noticed a lot of ajax jQuery requests, as shown below:

$.ajax({url: "../dir/someFile.json", method: 'post', dataType: 'json', error: function(...){ ... }, success: function(...){ ... } }); 

I would obviously use the get method, since no data is sent to this request. This probably happened when a teammate copied and pasted the code. This works great and there seems to be no good reason to change it to 'get'.

I think that using the get method will be faster in this case, but I have not found sources to confirm this.

+8
jquery ajax
source share
4 answers

There is some research that shows that some browsers will split the POST request into multiple packages. This can affect performance, which, in your opinion, will make the request slower. But in tests it seems that POST can sometimes be faster. I am not sure why this is so.

However, in practice, the difference in performance is not significant, and you should use POST and GET, as expected.

Reading:

+3
source

At least with historical versions of IE, there is a problem of transmitting the POST of an additional package. Some discussion of this here:

http://josephscott.org/archives/2009/08/xmlhttprequest-xhr-uses-multiple-packets-for-http-post/

I do not know how appropriate this is with the current browser visit.

The following are the results of the tests described in the article:

  • IE 6 - 2 packages
  • IE 7 - 2 packages
  • IE 8 - 2 packages
  • Firefox 3.0.13 - 1 package
  • Firefox 3.5.2 - 1 package
  • Opera 9.27 - 2 packages
  • Safari 4.0.3 - 2 packages
  • Chrome 2.0.172.43 - 2 packages
+2
source

All things being equal, there is no difference in network performance between GET, POST, or other methods. It all depends on how the server processes the GET and POST request. The server may, for example, try to update the resource in POST, but look for it only in GET.

In addition, with GET you can send data. In jQuery, it simply serializes to the query string ( $.get("someplace", data: { foo: "bar" }) sent as $.get("someplace?foo=bar") ).

0
source

This may seem obvious, but when using POST and GET, you use another byte in the method name.

In addition, if you have (several) data to send, using GET will encode the URLs (this means that the number of bytes generated and sent will be larger than the data size itself), while POST will consume more bytes (in general case), since the request additionally contains the Content-Type: application/x-www-form-urlencoded header Content-Type: application/x-www-form-urlencoded , probably the Content-Length header, as well as the same URL-encoded data as the GET.

If you have some binary data to send, the question is not fulfilled, since you cannot do it with GET.

We are talking about pennies here, but if you accumulate pennies ...

In the end, the GET request will be shorter and for the same network bandwidth will be faster than POST.

To send binary data, PUT will be faster than POST (based on the same logic and because POST will use multipart/form-data header headers), but browser support is more limited for PUT requests.

0
source

All Articles