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?
- By default no proxy server or web browser is caching this data, you will always get the real data from you web server.
- 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.
- Character encoding can be done easily using application/x-www-form-urlencoded.
- Running a http request with GET can be cached on your web browser or a configured proxy server.
- 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.
- 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)
- 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]
- 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?
Update: With Firefox 2 I need 7660 msec using POST and 5953 msec for GET. I love Internet Explorer 7!