tags:

views:

85

answers:

4

I like that, these days, we have an option for how we get our web content from the server: we can make an old-style HTTP request (with its own URL in the browser) or we can make an AJAX call and replace parts of the DOM on the fly.

My question is this: how do you decide which method to use when there's an option to use either?

In the "old days" we'd have to redraw the entire page (including the parts that didn't change) if we wanted to show updated content. Now that AJAX has matured we don't need to do that any more; we could, conceivably, render a "page" once and just update the changing parts as needed. But what would be the consequences of doing so? Is there a good rule of thumb for doing a full-page reload vs a partial-page reload via AJAX?

+2  A: 

My simple rule:

Do everything ajax, especially if this is an application not just pages of content. Unless people are likely to want to link to direct content, like in a blog. Then it is easier to do regular full pages.

Of course there are many blended combinations, it doesn't have to be one or the other completely.

Geoff
+1  A: 

A fair amount of development overhead goes into partial-page reloads with AJAX. You need to create additional javascript handlers for all returned data. If you were to return full HTML blocks, you would still need to specify where the content should go and whether or not it's replacing other content. You would potentially have to re-render header tags to reflect content changes and you would have to implement a history solution to make sure search engines can index each page (using SWFAddress jQuery plugin, for example). If you return JSON encoded data you have an additional processing step.

The trade-off for reduced bandwidth usage by not using a page refresh is offset by an increase in JS code and event bindings which could affect page rendering speed as well as visual effects.

It all really depends on your target audience and the overall feel you are trying to go for on your page. AJAX and preloaders are flashy, and people love flashy things. If you believe the end-user experience will improve by adding partial page loads by all means implement them.

cballou
A: 

In a state-of-the-art MVC architecture you have a request dispatcher which detects what kind of request comes in. Each request to your code goes trough this dispatcher. It takes the request and decides which function/class to call, and adds the parameters and other (HTTP, wascalledbyjavascript) information.

powtac
Who mentioned anything about using state-of-the-art MVC architecture? AJAX/Http requests can be used just the same whether the page is in a single file or is made using a complex web architecture.
James
+2  A: 

If you want people to be able to bookmark individual pages, use http requests.

If you are changing context, use http requests.

If you are dividing functionality between different pages for better maintainability, use http requests.

If you want to maximize your page views, use http requests.

lots of good reasons to still use http requests - Stack overflow is a wonderful example of those divisions between AJAX and HTTP request. Figure out why each function is http or ajax and I'm sure you will derive lots more reasons when to use each

MikeEL