views:

61

answers:

2

I would like know how browser executes/processes the request. I would like to know this because knowing how it works will help me understand how better web programming can be done which meets performance goals using browser features.

  1. How browsers download CSS, JS and Image files?

  2. Does it download one resource at a time or multiple?

  3. How many parallel requests (connections) it can make?

  4. What happens if request is getting executed on the server and user click on the stop button? Will the execution get complete and response will come back? Or on server site the request is suspended in half way?

  5. How JS execution is handled by browser?

Please add helpful links/information if possible. Thanks all,

A: 
  1. In the usual way (e.g., http GET operation, etc.).

  2. It's implementation-dependent, different browsers do it differently.

  3. It's implementation-dependent; typically, though, no more than two at a time between the same two endpoints (e.g., that browser talking to the same server). May be more if retrieving from multiple servers. Other resources get queued and wait for a slot to open up. This limit is typically enforced by browsers, but may also be enforced by servers (so a browser with this limit lifted may still find that later requests sit waiting for a bit while the server queues them.).

  4. It depends a lot on when they do that, what kind of server it is, etc.

  5. In strict document order. The browser may download multiple script files simultaneously, but it will execute them in document order. This is very important. Further processing of the page may (probably will) get held up waiting for the script to get downloaded and run. (IE supports the defer attribute on script tags that lets you tell it that it can continue processing the page before it executes the script.)

T.J. Crowder
+4  A: 

Please consider splitting this up into multiple questions. Here is some relevant information:

  • A web browser, or any web client, who wants to retrieve an HTTP resource will construct a GET request. This contains information to route the request to the proper server, and information to tell the server which resource is being requested. A resource can be an HTML page, an image, a Javascript file, or anything else.

  • When the browser receives an HTML page, the page may have links to other resources (for instance, image tags). These instruct the browser to make further requests.

  • Multiple resources may be downloaded in parallel. This can happen if your browser is attempting to load multiple pages at once (like in different tabs), or if the browser has received an HTML page that points it to several resources (as in the last point). From a single hostname, the HTTP 1.1 spec says that at most two resources should be downloaded in parallel (though this is just a guideline and cannot stop a browser from attempting to do otherwise).

  • Javascript is interpreted by the browser, just like other scripting languages are interpreted by their respective engines.

danben