What is a Browser?
1. A browser is a program or a software that interprets the markups and scripts of a webpage and displays it to the user. Eg: Google chrome, Internet Explorer, Firefox etc.
2. When a webpage is loaded, it is parsed from top to bottom using an interpreter which then renders content as per the markup and CSS and executes the scripts.
The ECMAScript : The specification specified by ECMA-262, it prepares the base upon which more robust scripting language can be created
The Document Object Model(DOM) : The DOM creates a map of the webpage as a hierarchy of nodes, with each HTML element as a Node containing different kind of Data. Script is used to target the specific node and then manipulate it.
The Browser Object Model(BOM) : The BOM is used to control the browser windows and frames, it enables the developer to pop-up new windows, close, resize and move browser windows.Get detailed information about the browser using the navigator object etc.Note: These concepts will be explained in great detail with examples in later chapters.
2.Care must be taken to see that the string </script> must not appear in the code, or else it results in an error as browser assumes it as the closing tag.
2. The problem with this approach is that the resources must be downloaded , parsed and interpreted before the page is being rendered(displayed) in the browser. If the size of code is large then there is noticeable delay in rendering of the page.
3. Hence modern developers include all references in the <body> element after the main content, thus page is displayed completely first while the resources are downloaded, parsed and interpreted in the background alongside.
Example: CSS Display - inline-blockGive it a TRY! » Note: The element is displayed as an inline element, but margin and padding can be applied (possible only for block-level elements.)
.1 The <script> element's attribute defer is used to indicate to the browser that the script must be downloaded immediately by the execution of the script is delayed.
.2 The script is executed after the entire page is parsed, i.e after the browser gets the closing </html> tag. The purpose is to denote that the structure of the webpage won't be affected by the script.
1. The <script> element's attribute async is similar to defer, that is it delays the execution of the scripts till closing </html> tag is parsed while beginning to download the files as soon as the page is loaded.
2. The only difference with attribute defer is that, the order of execution of scripts is not as specified.