How to build Graceful Degradation AJAX web page?
- by Morgan Cheng
I want to build web page with "Graceful Degradation". That is, the web page functions even javascript is disabled. Now I have to make design decision on the format of AJAX response.
If javascript is disabled, each HTTP request to server will generate HTML as response. The browser refreshes with the returned HTML. That's fine.
If javascript is enabled, each AJAX HTTP request to server will generate ... well, JSON or HTML.
If it is HTML, it is easy to implement. Just have javascript to replace part of page with the returned HTML. And, in server side, not much code change is needed.
If it is JSON, then I have to implement JSON-to-html logic in javascript again which is almost duplicate of server side logic. Duplication is evil. I really don't like it. The benefit is that the bandwidth usage is better than HTML, which brings better performance.
So, what's the best solution to Graceful Degradation? AJAX request better to return JSON or HTML?