1

I read this article here that talks about progressive enhancement for javascript and the author mentioned:

First, build an old-fashioned website that uses hyperlinks and forms to pass information to the server. The server returns whole new pages with each request.

Now, use JavaScript to intercept those links and form submissions and pass the information via XMLHttpRequest instead. You can then select which parts of the page need to be updated instead of updating the whole page.

I'm a little curious if does that means returning html markups at the server side instead of json, which usually means building the markup on the client side? Is there a disadvantage for this approach?

Also, I notice applications, for instance Facebook, looks pretty crippled when I disabled Javascript (can't post updates etc.) Does that means that it does not handle graceful degradation properly?

goh
  • 27,631
  • 28
  • 89
  • 151

3 Answers3

4

Does progressive enhancement means no json with ajax?

No, it most certainly does not mean that. If JavaScript is disabled, there is no XMLHttpRequest, so there is no ajax.

Now, use JavaScript to intercept those links and form submissions and pass the information via XMLHttpRequest instead.

The JavaScript bits that intercept links and form submissions can freely change where the requests are made, URL parameters, and so on, which means that ajaxified URLs don't have to be identical to JavaScript-less ones. For example:

<a href="/some/page.html">linky</a>

could be intercepted and turned into an XMLHttpRequest which is actually made to

  • /some/page.json, or
  • /some/page.html?ajax=1, or
  • /bibbidi/bobbidi/boo (for all that it matters)
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • matt, what i actually meant was if javascript is disabled, urls should return markups. However, if javascipt is enabled, then should the ajax request to the same url return the same markups or should it return json and use javascript to parse and create the markup? – goh Jun 05 '11 at 04:32
  • If JS is disabled, of course the URLs need to point to proper HTML pages. – Matt Ball Jun 05 '11 at 04:33
  • If JS is enabled, and you don't want to change the URL, you need _some_ way to signal to the server that it's an ajax request, and you'd obviously have to program the server to reply with a different output format accordingly. A query parameter (as in `/some/page.html?ajax=1`) would do the trick. – Matt Ball Jun 05 '11 at 04:35
0

Progressive enhancement means that you start the page with code that will work everywhere, and then progressively add functionality that is accepted by that user's browser. A good example of this is on ajax type functionality with anchors. When the page loads, you can use urls in the hrefs so that spiders and non-javascript browsers can still get the content. But you also add an onclick that does the ajax loading. That way both the enabled and disabled clients get the best behavior that they can.

hivie7510
  • 1,246
  • 10
  • 23
  • This means that the spider can follow the link to get the content, and the javascript enabled browser can use the onclick to load the data without a full page refresh. Both user agents get the best experience. – hivie7510 Jun 05 '11 at 04:10
0

Essentially, progressive enhancement means you place the priority and importance of building a fully working "no-Javascript" website first, then slowly enhance your website by adding the Javascript functionality and then AJAX, while keeping the "no-javascript" features working.

This is just to allow those who have Javascript disabled to access and use the site as per normal.

mauris
  • 42,982
  • 15
  • 99
  • 131