Nosrettap
Nosrettap

Reputation: 11340

Does the browser start rendering HTML when the first data packet is recieved

In a web browser (mobile if that matters), I assume that when you access a webpage a number of packets of HTML data are returned. If that is correct, do web browsers begin rendering the HTML before all of the HTML packets have been returned?

I ask this because I'm writing a webpage and I've heard that above the fold content should have lower latency than below the fold content and I was wondering why this would matter if the browser waits for the entire HTML response before processing.

Upvotes: 1

Views: 612

Answers (1)

user149341
user149341

Reputation:

Yes, web browsers will generally attempt to render pages based the data they have available if only part of the content is available within a short time period. The rendered page is updated periodically as more content becomes available.

Keep in mind, however, that certain factors may prevent a browser from rendering partial content, especially:

  • External <script> elements within the body of a document halt rendering until the script can be loaded. (This is because the external script may contain calls to document.write(), which could change the interpretation of the document.)

  • Some browsers cannot render HTML tables until the entire table is available.

  • Browsers will usually attempt to download stylesheets before rendering the page, to avoid a FoUC ("flash of unstyled content"). If the stylesheet doesn't arrive, though, browsers will eventually give up and work with what's available.

  • Some web application frameworks and/or programming languages may have features which prevent any content from being sent until it has been fully generated.

Upvotes: 4

Related Questions