1

I have a script which when accessed with the HTTP protocol will send some data, pause for a few seconds, then send some more data, repeating until all the data is sent.

When I access it in curl, it behaves as expected, and sends the data piece by piece. However, if i try to access the page in a browser, nothing is displayed on the screen until the entire script has finished running, several seconds later.

You can observe this behavior (temporarily) by accessing the URL

curl 'http://50.80.82.137:8000'

Then try the URL again in a browser and notice how the script waits for about 7 seconds before it loads anything, even though it should have access to the first lines immediately.

What is the source of this behavior?


It's written in NodeJS, and I put it up on GitHub for reference. However, in this case I'm assuming the language involved is irrelevant (which is why I asked it on SuperUser instead of StackOverflow, and any script which has a "pause" before sending data will behave in a similar fashion.

  • 1
    I'm assuming the browser buffers the data to make the HTML easier to parse, but I'm not sure where to find details on or reference works regarding this behavior. – IQAndreas Jan 4 '15 at 15:04
  • the q is fine here but you might get a broader user base if you asked this on SO and it may be ok on SO – barlop Jan 4 '15 at 23:42
  • @barlop Completely off topic (so I will delete this comment when you have read it), your profile has had 1,886 views over the last four years, yet you haven't added any description, nor a link to your website. You are missing out on a lot of free (and well deserved) publicity. – IQAndreas Jan 5 '15 at 1:16
2

A web browser can't start processing a web page until the entire HTML document has completed downloading. Once the HTML has downloaded it can be parsed and rendered, but not before.

Curl doesn't need to wait for the whole document since it doesn't parse anything, it just prints everything to StdOut as soon as it arrives.

Use client-side tools (Javascript, CSS, etc.) to affect client-side behavior, not the network protocol.

  • Is there any documentation on that which you could supplement your answer with? (or even a link to the relevant part of FireFox's source code which shows this "waiting" behavior) – IQAndreas Jan 18 '15 at 4:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.