是否使用AJAX [关闭]

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        As it currently stands, this question is not a good fit for our Q&amp;A format. We expect answers to be supported by facts, references,   or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question   can be improved and possibly reopened, <a href="/help/reopen-questions">visit the help center</a> for guidance.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2011-08-11 21:21:40Z" class="relativetime">8 years ago</span>.</div>
        </div>
    </aside>

This question might get closed, but I am looking for a bit of a brainstorming session.

I am setting up a portfolio site for my articles, and I am going to bring in feeds of all my articles straight from the sites they are posted on via their RSS feeds.

The site is powered by Wordpress so I will be using Shortcodes to set out which sites the articles are coming from, the question I use AJAX or PHP to bring in the RSS and parse it.

I can use the shortcodes to set up a div with the url for the RSS feed as a data attribute, data-content-url='', or I can simply write the parsing function in PHP and link it straight from the shortcode parser. Note, I will be parsing in PHP for non-js users anyway, the question is should I bother with the progressive enhancement to AJAX or not.

AJAX has the benefit of speeding up the page load time, because I can load the page then bring in the feeds afterwards, but when I am working with the shortcodes in php anyway, it struck me that maybe I should just do it all while I was at it. My main reason for wanting to do AJAX if I'm honest is to try out the new multiple request API with .when and .done

</div>

With any question that asks if they should do AJAX I always the same thing.

You should make your application in a way that it doesn't depend on AJAX. This is a lot of reasons like what if js is disabled or what if something else goes wrong. When you assume everybody has javascript is enabled you still lose about 5% of people who disable it. The best design is to use AJAX as an extension to your website. What do I mean by that?

<a href="some_page.html" ajax="true">To another page</a>

This is the basic HTML one would need. There is nothing here that makes the user need javascript to use it.

Now to improve the above experience for people who do have js enabled you can do

$("a[ajax=true]").click(function(){
  $("#content").load(this.url + " #content > *);
});

With the above design, everybody can use your website and with people who hava js enabled will see a better experience.

Also note that you can use the power of .load() method to load a part of the remote page. This way you don't need to create multiple pages.

Amir has made some good points. Given that I'm currently working on a rebuild/redesign of a very valuable site from scratch, the use of AJAX was something we considered carefully. While I favour the use of AJAX where possible there are 2 situations in particular where I won't use it or at least, will make sure there's a rock solid fallback.

The first is, unfortunately, Amir's example. Pages should be loaded with an actual request to the page that serves the full page. The only place I sometimes don't do this is an admin interface where there are no concerns about SEO. While Amir does suggest have a fallback where the page wouldn't load via AJAX, this is a case where you're really just increasing the complexity of your site and user experience (either your back button won't be functional or you'll have to also use a library that deals with browser history to keep back/forward function in the AJAX version).

The second situation where I will attempt to always make sure there is a fallback is any kind of form. Be it for a comment, a calculator or some revenue generating aspect, forms are an important way a user interacts with you site. Ideally, where possible and appropriate, forms should (personal opinion) be done with AJAX. It generally improves the user experience as you can add nice loading gifs etc... Good user feedback is a major plus and is much better than a non AJAX version where they just see the browser churning until the page comes up.

That being said, as forms are a major interaction point, you can't afford them breaking so they should ALWAYS work without AJAX. It's not even a matter of the 5% of users (some of which I expect is actually devs testing their sites on production environments :-P ) with javascript disabled. What if your javascript has an error? Or maybe you've used a function that doesn't exist in all browsers so again, your javascript errors in some browsers? In those situations you want your forms to still work so it is vital to make sure they fallback to non AJAX versions.

My advice would be to always build your site to work without AJAX 100% then look for places you feel can be improved by the use of AJAX and add it as a layer on top. This will help give you the confidence that beneath the javascript, you site is rock solid.