How to Build a Graceful Degradation AJAX Web Page?

I want to create a web page using Graceful Degradation. That is, the function of the webpage is even javascript disabled. Now I have to make a design decision in AJAX response format.

If javascript is disabled, each HTTP request to the server will generate HTML as a response. The browser is updated with the returned HTML. It's fine.

If javascript is enabled, every AJAX HTTP request to the server will generate ... well, JSON or HTML.

If it's HTML, it's easy to implement. Just replace the part of the page with the returned HTML. And, on the server side, a lot of code changes are not required.

If it is JSON, I have to again implement the JSON-to-html logic in javascript, which almost duplicates the server-side logic. Duplication is evil . I really don't like it. The advantage is that bandwidth usage is better than HTML, which provides better performance.

So what is the best solution for elegant degradation? AJAX request is it better to return JSON or HTML?

+2
source share
3 answers

I don’t think there could be a “better solution” for any situation. Only, perhaps, a “suitable solution” for a particular one. It really depends on what you are trying to do. What elegant degradation means to me:

  • "" , ( ).
  • ( , , - ), , , , , .

HTML JSON , . , , - , , , , . . , , .

, JSON , JSON . ( , ). , , - //gzip , , . , (<strong></strong>). , JSON , . -, (, - , ).

- . :

http://www.quirksmode.org/blog/archives/2005/12/the_ajax_respon.html

+3

IMO, HTML ( MITM script ..). , "", .

JSON , , , .

, (JSON).

0

, , JavaScript, . , AJAX , ( HTML) .

, :

  • , , , ( , ) . - , , - . - , , , XML.

  • script, XML.

  • script, HTML-.

  • , , javascripts, (, ), AJAX script, . NOSCRIPT, , JS-, , script. , , .

0

Source: https://habr.com/ru/post/1765650/


All Articles