robocat 6 hours ago

For our SPI an important optimisation was to selectively force critical JavaScript to be inline (and avoid script defer or async).

The standard browser heuristics were incorrect in our circumstances: which led to suboptimal page loading in the browser (the heuristics slowed down the critical part of page load). To indicate to a browser that JavaScript is on the critical path, you need to use inline scripts. It also required a ton of work to avoid giving the browser a chance to context switch.

Part of our loader code would request the same JavaScript from two locations (from both a CDN and from our host) and only evaluate the first response and cancel the redundant request. The JavaScript files were relatively small so the device the browser was running on was rarely bandwidth constrained. The primary reason was to make the page load reliably (files sometimes fail to load - requesting the same file from two locations really upped the reliability. The CDN didn't always win the loading latency race for a variety of reasons.

There's a lot of optimisations that can speed up page load but some require doing what appears odd unless you've very carefully profiled real customer browsers.