Which elements will load first in an html page?
I want to know which elements (html tags, scripts, styles, images) will load first when opening a web page?
Can anybody help 开发者_高级运维me? Thanks in advance.
There is no standard way; browsers are free to implement this in any way they like.
If you want to know how your browser does it, use a tool like Firebug, Chrome's Developer Tools or Safari Inspector. They can show the network traffic and in which order elements are downloaded.
Usually, the download order is the same as in the HTML document but browsers can open more than a single connection to a server. In that case, it might send 2 or 5 requests in document order but the server can respond in arbitrary order. Also some parts might be loaded from cache.
HTML pages are interpreted on the fly and read in their entirety from top to bottom - so, the first elements will load first, the last last.
For instance, if you place a script at the top of the body
then it will be executed prior to any elements within the body loading; whereas if you place is at the end of the body
, all elements within the body will load then the script will execute.
The order of loading for external sources such as scripts and images, though, might differ from browser to browser (while for the most part following the same conventions) - the idea is that connections will be open to request these resources and then things like size, speed and latency come into question - and these are most often still sequential and blocking.
The html will load first obviously as this instructs the browser on the extended requirements: images, scripts, external stylesheets etc
After that, the load order is pretty random - multiple connections will be initiated by most browsers and the order in which they return cannot be predicted.
Execution start from Top to bottom ...
Html and its shit go top bottom, scripts and css less read bottom to top. The code is written this way because each is part of a list and it is being set in descending order on one path; Ascending on the other path. The Journey can shift if your files are stacked differently, thus the argument of 'where shit goes'... So the Html divs down to a Head; And then the body sets us up. Set your javascript script tags in the area of the html itself using the script tags. This might seem a bit much but creating an id tag to a script in that area will set the script when that section is called for instance. Same goes with css and stuff. SO I think like that and typically get fast loads on some neat parallax pages I have on johnaldrin.net if anyone is interested. I always have no paintings and sample scripts to play with, custom ASP web forms... Digital ARt mixed with fun Meta tags, driving an SEO Engine I developed in .NET C#!
精彩评论