Notes

The Browser Object Model

The DOM vs the BOM

The Browser Diagram

img of browser diagram
img of browser diagram

The Request/Response Cycle

The Request Response Cycle Diagram rr cycle

The Browser’s Role in the Request-Response Cycle


Running JS Scripts in the Browser

Using the Window API

// windowTest.js

// Open a new window
newWindow = window.open("", "", "width=100, height=100");

// Resize the new window
newWindow.resizeTo(500, 500);

Context, Scope, and Anonymous Function


Running a script on DOMContentLoaded

window.addEventListener("DOMContentLoaded", (event) => {
  console.log("This script loaded when the DOM was ready.");
});

Running a script on page load The alternative to DOMContentLoaded is, waiting for everything to load in the document before we run our script. For this we can use window.onload

window.onload = () => {
  console.log(
    "This script loaded when all the resources and the DOM were ready."
  );
};

Ways to prevent a script from running until page loads Some methods include:

  1. Using DOMContentLoaded in an externel JS File.
  2. Put a script tag importing external code at the bottom of HTML file.
  3. Add attribute to our script tag such as async or defer.
  <script async src="scriptA.js"></script>

  <script defer src="scriptB.js"></script>

  <script async defer src="scriptC.js"></script>