Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.


page loading & asynchronism

reminder : a few orders of magnitude

  • CPU + memory : 1 ns

  • storage :

    • SDD : 100 µs

    • HDD : 1-10 ms

  • USB transfer latency : 1 ms

  • networking :

    • light-speed Paris-SF : 30 ms

    • light-speed Paris-Nice : 3 ms

    • plus, software stack traversals

    • plus, protocols = several back and forths

    • bottom line: more in the several 100s of ms

    • frequently several seconds


a simple page

when loading the simplest possible page, contents get scattered into packets
so it does not arrive all at once


a page with a nested page

if e.g. the html page uses one CSS stylesheet,
there are 2 HTTP requests at work - essentially at the same time


loading a real page

Devel Tools can visualize the actual loading workflow


JS loading - howto

open topic


simplest case

for our use case, it’s simple though:
we have a single HTML page, that needs to load one JS fragment
and the good news is, there is one simple way : the <script> tag, that comes in 2 flavours:


<script src="..."> : load a URL

most often, code is stored in a separate location

for that, use <script src="some-url"></script>


deferred loading

very convenient: by using <script defer>, you can ensure that the script runs only once the entire page is loaded

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

<script> with inline code

  • quite simply, you can inject some JS code right into your HTML document, through a <script> tag

  • this is not the usual way to do it though (for reusability, primarily)

<script>

  function hello() {
    console.log("Hello world");
  }

  hello()

</script>

practice: <body> children count