tags:

views:

482

answers:

2

Whats best in terms of performance/speed when considering a ASP.NET ajax server page which returns results back to the ajax calle in the javascrit ? an ASPX file or ASHX ?

A: 

I've not compared but I think if you are using Page Methods then they should perform comparably to ASHX as there is not extra calls to other methods except the once specified in ajax request.

TheVillageIdiot
Page methods require an entire page lifecycle process, unlike asmx services or ashx handlers. Page methods are convenient, but sacrifice some performance. To demonstrate this, try setting a breakpoint in page_load and calling a pagemethod.
David Lively
+1  A: 

I think the most important question is whether or not the result is cacheable, and if so, if it is publically or privately cacheable.

If the service is just a data lookup (as opposed to a call that actually modifies data), then you can set response headers that enable client side caching. If the data is also public data, then you can set the response headers so that proxy servers etc. can cache the data. And if the data is requested often, that can take some load off your web server.

But that requires the request to be an HTTP GET operation, which an ASHX file can handle. But the WebMethod will generate an HTTP POST.

So if enabling client caching of the response makes any sense, go for ASHX. If the data changes every second, for example, then it doesn't make sense to enable client caching. And if the request actually modifies data then it doesn't make sense to cache the data client side either.

Otherwise I don't think that there is any serious performance concern of the one method or the other.

Pete