Multiple Scripts

I learned recently that web browsers will execute an HTTP request for each <script> tag they find in the document. I hadn't really thought much about it, assuming a kind of declarative interpretation of HTML, where when multiple <script src="foo.js"></script> show up in the document, only one would be requested and executed. Turns out my assumption is wrong and the browser will happily request the same script multiple times. It's not much of an issue in practice, on subsequent page loads the browser will hit its local cache for every script load.

I have a number of "builtins", invokable functions, in the site's templating language. For example, date which parses and calculates date formats:

{date(post.md.created, rel-date)}

After a few calculations, this used to output HTML like:

<span class="rel-datetime" data-datetime="2025-07-25T23:06:48Z">2025-07-25</span>
<script defer src="../scripts/time-utils.js">

On pages like the blog frontpage this results in like 20 unnecessary script loads 🤦‍♂️. The issue is fixed now — I set up a sidecar that builtins can put scripts into where they are deduped and then inserted into the page.