POST vs. GET

Tags: AJAX, JavaScript

I'm reading a lot of performance issues when using POST instead of GET in AJAX enabled web applications. What are the key benefits of each http method? And is POST really slower than GET?

POST

  1. By default no proxy server or web browser is caching this data, you will always get the real data from you web server.
  2. The length of data you can send to the web server is only restricted by the web server itself, but there is no real restriction.
  3. Character encoding can be done easily using application/x-www-form-urlencoded.

GET

  1. Running a http request with GET can be cached on your web browser or a configured proxy server.
  2. To get the live data from you web server you have to modify the url that is used in your XHR invoke, simply by using a counter or new Date().getTime() which will generate a unique url.
  3. Maximum URL length is 2,083 characters in Internet Explorer (see MaxClientRequestBuffer: Use POST instead of GET to Send Large Amounts of Data in Request)
  4. In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. [RFC 2616 sec 9]
  5. Character encoding will reduce the amount of data that can be used because of url encoding entities (i.e. three Japanese characters are converted to this: %26%2312454%3B%26%2312455%3B%26%2312502%3B)

 

If I use Ethereal to watch a POST and compare it with a similar GET I can see that there could be one more request/response because of the http 100 Continue response. I put a very simple example online (currently only working with IE7) at http://www.ajaxpro.info/xhr_post_vs_get.aspx. If I run this example here in Germany I get something like 4 seconds for each, cannot see any difference. My friend Sonu tried it and got 21806 for POST msec and 21913 for GET. So, where is the slowness using POST?

My conclusion is: use GET if you want to cache data in your local web browser cache, but be careful if you have old JSON data in your web browser cache that is maybe not compatible with you JavaScript code. If you have to save data like submitting a form you should use POST. I would be happy to get your thoughts about using POST vs. GET.

Update: With Firefox 2 I need 7660 msec using POST and 5953 msec for GET. I love Internet Explorer 7!

1 Comment

Comments have been disabled for this content.