tags:

views:

608

answers:

11

Very much Webpages loading all their content to change little informations. Now i would like to know why shouldn´t the developers use ajax for the main page requests? I will like to develop the main requests on my webpage with ajax but i dont know any cons.

Has anybody an idea why anybody shouldn't use ajax so much?

+1  A: 

The biggest con are users who have JavaScript disabled. Your website simply won't work for them.

Daniel Lew
+2  A: 

I'll give you one very good reason.

If you turn off javascript in the browser it won't work.

Vasil
+11  A: 

Search engines, crawlers/spiders, browsers with no javascript, screen readers and other consumers of the content will not be very happy with it.

You can provide tons of ajax behavior on top of you website if you already support standard server side navigation for the full content. Have a look at progressive enhancement (SO) and progressive enhancement (wiki).

cherouvim
How can you be unhappy with something you can't even see in the first place? :)
Tyson
You won't be happy because your website will be SEO unfriendly. Generally there are techniques which mitigate these issues (for rich websites in ajax or flash) such as sitemaps protocol, but the best thing you can do for yourself and the web in general is to design your website's flow in pure HTML!
cherouvim
A: 

Aside from the answers already posted, using AJAX can have ugly side effects on browser control, such as the stop button not working.

Boden
+4  A: 

The whole premise really is that with AJAX you don't need to reload the whole page to update a small percentage of that webpage. This saves bandwidth and is usually much quicker than reloading the whole page.

But if you are using AJAX to load the whole page this is in fact counterproductive. You have to write customised routines to deal with the callback of the AJAX data. Its a whole lot of extra work for little to no increase in performance.

General rule for where to use AJAX: If your updating >50% of your page, just reload, else use AJAX.

Gary Green
Besides the obvious reasons listed by cherouvim, this is a huge one - *there's no point*
annakata
A: 

One thing is that you want content to have a static url, you want people to be able to link to your pages, bookmark them, etc.

If everything is ajaxified, this could be tricky and/or tedious.

hasen j
There are good libraries for getting around this issue: http://code.google.com/p/reallysimplehistory/
Daniel Lew
A: 

Yes, i understand the cons which anybody wrote. But when i will that my page works for anybody then i can´t use ajax anytime. I think more then 90% are using javascript on their homepage and without javascript nobobdy can go through the world wide web.

Thank you very much.

Turn of javascript in your browser than visit 10 different major news, gaming, social networking sites and you'll see that they always develop for this eventuality. The simple fact that crawlers can't index your site is reason enough not to do it.
Mike B
'I think more then 90% are using javascript on their homepage and without javascript nobobdy can go through the world wide web.' - Think again about that. I turn on noscript in firefox on sites that look like they've been coded by monkeys in case there's an xss somewhere.
Vasil
A: 

Well if you want to AJAX load new pages, such as the same way Gmail works, I suggest your links are normal A HREF links that point to a true full rendering page URL and alos use an onclick event that stop the attempt at normal link loading and make your AJAX calls. The problem here is you'll be doing almost double coding unless you architecture this all very well.

This way the normal non JS links load the full page, and the JS calls only load the new parts or page. This means spider indexing works again too.

TravisO
A: 

at TravisO:

i use jquery for my request and i think if i define the href in the element then the click() event from jquery doesn't work.

But i think your way is a good idea.

A: 

Well, you can always add the onclick event unobtrusively using jquery and stop the normal URL handling.

Eg:

HTML

<a id="ajaxify-this" href="my-working-url">Click me to do AJAXy stuff if you have javascript</a>

then Javascript

$(document).ready(function() {       
  $("#ajaxify-this").click( function(e) {
       updateContent(); // do something ajaxy with the page
       return false; // stop the click from causing navigation
   })
}
sabbour
i solved the conflict better.... ;)$(document).ready(function() { $(".nav").removeAttr("href");});if js is active, then jquery disabled the href content and i can usemy ajax calls... :p
you could also have usede.preventDefault();insteas ofreturn false;
sabbour
A: 

I use only JavaScript and EJS as template Engine for my own webside. One step closer to SOFEA/SOUI.

Search engines, crawlers/spiders, browsers with no javascript, screen readers dislike it, right. But I follow the mainstream ;)

Martin K.