Craig Walker
Craig Walker

Reputation: 51787

Getting content: AJAX vs. "Regular" HTTP call

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?

Upvotes: 14

Views: 13845

Answers (3)

MikeEL
MikeEL

Reputation: 674

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 requests. Figure out why each function is HTTP or AJAX and I'm sure you will derive lots more reasons when to use each.

Upvotes: 17

Corey Ballou
Corey Ballou

Reputation: 43547

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.

Upvotes: 4

Geoff
Geoff

Reputation: 9340

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.

Upvotes: 4

Related Questions