It405 Week 06

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

IT405: E-Portals Development

Building a Web 2.0 Portal with ASP.Net 3.5


Al Zabir, Omar (2008)
Chapter 6: Optimizing ASP.NET AJAX
Objectives
Understand combining multiple Ajax calls into one
call.
Describe timing and ordering ajax calls to the server.
Recognize caching web service responses on the
browser.
Explain using HTTP GET calls instead of HTTP POST.
Identify working with the this function
Combining multiple Ajax calls into one
call
It is important to reduce the number of calls made to the
server to reduce network roundtrip which is costly.
Ajax developers batch multiple consecutive single calls
into one large call for efficiency and effectiveness.
Timing and ordering Ajax calls to the
server
Browsers make a maximum of two concurrent Ajax calls
to a domain.
If more than two calls are made, the browser will first
make two calls and queue the remaining.
The browser will wait other calls to complete, and then
make another call until all queued calls are complete.
However, the calls will not execute in the same order as
made.
Timing and ordering Ajax calls to the
server

Problem: To eliminate bad calls from forcing good calls to time out and
create time
Solution: modify the ASP.NET AJAX runtime and introduce automatic
retry.
Caching Web Service Responses on the
Browser
Browsers can cache images, JavaScript, and CSS files on a users hard drive.
They also cache XML HTTP calls if the call is an HTTP GET and not an HTTP
POST as the cache is based on the URL.
The browser will cache any HTTP GET call and return cached data based on
the URL.
Create an XML HTTP call as HTTP GET and the server returns a special
header.
The browser will cache the response which will be returned from the cache
on future calls.
This action saves the delay of a network roundtrip and download time
increasing client-side performance.
Using HTTP GET calls instead of HTTP
POST
ASP.NET AJAX, by default, uses HTTP POST for all web service calls which is
expensive. Instead use HTTP GET to reduce costs.
HTTP GET does not allow you to pass objects as parameters, only numerics,
strings, and dates.
When making an HTTP GET call, ASP.NET AJAX builds an encoded URL and hits
that URL up to 2,048 characters.
To enable HTTP GET on a web service method, decorate the method with the
ScriptMethod attribute.
Working with the this function
XML HTTP callbacks are not executed on the same context where
they are called.
If you are make a web method call from a JavaScript class you get
null on the debug console because this is no longer the instance of
the class, which is a common mistake.
When JavaScript events are raised that this refers to the HTML
element that produces the event.
Use ButtonID so the button is making the call. The call is made
within the button objects context so refers to the button object,
not the instance of the class.
Working with the this function (cont)
XML HTTP raises the event onreadystatechanged and
ASP.NET
AJAX traps and fires the callback.
The code execution is still on the XML HTTPs context.
Its the XML HTTP object that raises the event and refers
to the XML HTTP object, not your own class where the
callback is declared.

You might also like