{"id":9661,"date":"2021-01-13T16:03:48","date_gmt":"2021-01-13T16:03:48","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=9661"},"modified":"2024-02-16T10:49:12","modified_gmt":"2024-02-16T10:49:12","slug":"how-gets-a-webpage-loaded","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=9661","title":{"rendered":"Loading order of a webpage"},"content":{"rendered":"<p><strong>Basics<\/strong><\/p>\n<p>1. Fetch the requested HTML file (via HTTP GET).<br \/>\n2. Parse (creating the DOM) that file (using DFS).<br \/>\n3. Fetch every found linked item (e.g. IMG, CSS, JS) on the way.<sup>1<\/sup><br \/>\n4. Send DOMContentLoaded event after the DOM parsing is done.<br \/>\n5. Send window.onload event after everything is renderable.<sup>2<\/sup><br \/>\n6. Generate the layout and paint the web page.<\/p>\n<p><sup>1<\/sup> IMG and CSS are getting fetched in parallel, but JS blocks the DOM parsing.<sup>3<\/sup><br \/>\n<sup>2<\/sup> All IMG and CSS files has been fetched and the CSSOM has been parsed.<br \/>\n<sup>3<\/sup> That isn&#8217;t true if the JS file is linked with a <a href=\"http:\/\/www.max-sperling.bplaced.net\/?p=13604\">keyword (async\/defer)<\/a>.<\/p>\n<hr>\n<p><strong>Example<\/strong> (with async loaded JS)<\/p>\n<pre class=\"brush: xml; gutter: false; title: index.html; notranslate\" title=\"index.html\">\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;\r\n    &lt;script src=&quot;time.js&quot; async&gt;&lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;h1&gt;Birubi Beach&lt;\/h1&gt;\r\n    &lt;img src=&quot;http:\/\/www.max-sperling.bplaced.net\/wp-content\/uploads\/2020\/04\/Header_progressive.jpg&quot; \/&gt;\r\n    &lt;h4 id=&quot;currentTime&quot;&gt;&lt;\/h4&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<pre class=\"brush: css; gutter: false; title: style.css; notranslate\" title=\"style.css\">\r\nbody {\r\n  text-align: center;\r\n  background-color: grey;\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; gutter: false; title: time.js; notranslate\" title=\"time.js\">\r\nfunction writeTime()\r\n{\r\n  document.getElementById(&quot;currentTime&quot;).innerHTML = new Date().toLocaleTimeString();\r\n}\r\nsetInterval(writeTime, 1000);\r\n<\/pre>\n<p><u>Analysis<\/u> (with DevTools, &#8220;Performance&#8221; tab)<\/p>\n<p><a href=\"http:\/\/www.max-sperling.bplaced.net\/wp-content\/uploads\/2021\/01\/webpage_with_async_js.png\"><img decoding=\"async\" src=\"http:\/\/www.max-sperling.bplaced.net\/wp-content\/uploads\/2021\/01\/webpage_with_async_js-1024x100.png\" class=\"aligncenter\" \/><\/a><\/p>\n<pre>\r\nDCL ... DOMContentLoaded Event\r\nL   ... Onload Event\r\nFP  ... First Paint\r\nFCP ... First Contentful Paint\r\nLCP ... Largest Contentful Paint\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Basics 1. Fetch the requested HTML file (via HTTP GET). 2. Parse (creating the DOM) that file (using DFS). 3.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[55],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9661"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9661"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9661\/revisions"}],"predecessor-version":[{"id":16841,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/9661\/revisions\/16841"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9661"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}