Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do web applications send HTML over the wire?
    primarykey
    data
    text
    <p>This question pertains to web applications. I have very little web app development experience, so might be missing some very obvious points/issues. Please point them out.</p> <p>As I understand, in most web applications, a web server sends HTML over the wire to a client (browser). This happens every time a HTTP request is made. I feel this is very wasteful of bandwidth.</p> <p>1) Since browsers can run JavaScript, why don't we just send a JavaScript program which can generate the webpage's HTML content (which the browser then renders).</p> <p>2) Further a browser might cache the JavaScript program and next time the server only need send the data. The protocol might involve the browser sending the "program version" it has.</p> <p>Consider an example of a relatively simple website Hacker News [<a href="http://news.ycombinator.com]" rel="nofollow">http://news.ycombinator.com]</a>. Let us separate the data (30 posts + their metadata) from its presentation. Assuming 1) above, the server can just send the data (say in JSON) + a JavaScript program to generate HTML. This <a href="https://gist.github.com/782329" rel="nofollow">gist</a> shows the idea. The data for the 30 posts is in JSON [<a href="http://www.json.org/js.html]" rel="nofollow">http://www.json.org/js.html]</a> format. For this particular example the data transferred is cut in 1/2 (size of data+JavaScript / size of HTML). Further if browsers can do 2) above, it reduces the data transferred on each visit to 1/4 (size of data / size of HTML). [Note: this analysis is without considering compression; gzip,deflate is very successful in reducing the size of HTML. But isn't prevention better than cure?]</p> <p>I see atleast the following advantages of this :-<br> * For most web pages, it will reduce the size of data transferred over the wire.<br> * Forces web apps to separate data from its presentation.</p> <p>Disadvantages might include - more complex browsers, time to run the JavaScript program to generate HTML (this might get offset by the reduction in data size).</p> <p>Now my question is - why are web applications not developed this way, or, why do web applications send HTML over the wire? Surely the web server (sending out HTML) doesn't care about HTML at all, so why should it, first, generate it, and then send it over the wire?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload