User:Brahmana/Netwerk Docs/Image Loading

From MozillaWiki
Jump to navigation Jump to search

Images defy a lot of rules that the previous docs mention. The most of them being sharing channels. If there are multiple requests raised for a single image, and by single image I mean image file referenced with the same URI, then there is only one netwerk connection that is spawn for each of those requests(which are essentially channels) and all the channels are fed from the same underlying netwerk transaction. Note that this is different from caching. In case of normal requests the caching will work only when there is a request for a document, which was already requested earlier and the earlier transaction is over and the data is in the cache. But in case of images, even when multiple requests are simultaneous all requests are sort of bundled together and fed from the same netwerk transaction.

Note: By netwerk transaction I am not referring to the nsHttpTransaction class. Its used as a generic term. From what I know, mostly its the nsHttpConnection object that is shared amongst the requests. << This needs validation (Biesi/bz) ? >> [There may not be anything shared between the requests. They don't always reuse connections. --Biesi 15:53, 4 August 2008 (UTC)]

Another major difference is that rarely do any of the image load requests go through docShell. The requests arising from <img> tags, which are probably the highest, do not use docShell. docShell will come into picture only when an URI pointing to an image is loaded by entering directly in the URL bar.

So as of now I assume the request is created by the DOM parser when it starts parsing the base HTML page and finds <img> tags. [It's not really the parser that starts the requests, it's the DOM node (nsHTMLImageElement via nsImageLoadingContent) --Biesi 15:53, 4 August 2008 (UTC)] Since there is sharing of netwerk layer resources between multiple requests for the same image, the parser might as well wait, bundle all the <img> tags pointing to the same URI and then place requests for each bundle, instead of creating a new request for every <img> tag it encounters. << This needs validation (Biesi/bz) ? >> [I don't really understand what you are saying here. The bundling is currently done by the imgLoader. Are you suggesting that this is done at a different level? Why? Also keep in mind that it may be multiple tabs/pages sharing the image load --Biesi 15:53, 4 August 2008 (UTC)]

Note: Here, by request I am referring to an nsIRequest object, which I think is a nsIChannel in most cases.(Though at some point later the old request is replaced with an imgIRequest type).

The control flow for an image load is shown in the diagram. <<coming soon>>