by ko27 · 5y ago · 0 comments
2. How do you handle the performance impact of your browser doing multiple sequantial requests because it doesn't know your whole dependecy tree?
See my comment above.
> 2. How do you handle the performance impact of your browser doing multiple sequantial requests because it doesn't know your whole dependecy tree?
Put all your dependencies in the HTML file, so it fetches them all in parallel. So instead of just loading the root application file and forcing the browser to resolve dependencies:
<script type="module" src="/scripts/app.js" defer></script>
Load the dependencies like this: <script type="module" src="/scripts/lib/gui.js" defer></script>
<script type="module" src="/scripts/lib/guielements.js" defer></script>
<script type="module" src="/scripts/lib/network.js" defer></script>
<script type="module" src="/scripts/lib/input.js" defer></script>
<script type="module" src="/scripts/lib/rendering.js" defer></script>
<script type="module" src="/scripts/lib/sockets.js" defer></script>
<script type="module" src="/scripts/lib/world.js" defer></script>
<script type="module" src="/scripts/lib/ui/classupgrades.js" defer></script>
<script type="module" src="/scripts/lib/ui/toasts.js" defer></script>
<script type="module" src="/scripts/lib/netstore/minimap.js" defer></script>
<script type="module" src="/scripts/data/configuration.js" defer></script>
<script type="module" src="/scripts/app.js" defer></script>
You can see a demonstration of this technique on my production site, a complex JavaScript SPA that loads everything (including dynamic content) in less than one second: http://vnav.ioFor a small performance boost, you can load smaller files first via <link rel=preload>.
> Put all your dependencies in the HTML file, so it fetches them all in parallel.
> ...
> You can see a demonstration of this technique on my production site, a complex JavaScript SPA that loads everything (including dynamic content) in less than one second
But it doesn't work like this in practice! There is a limit to the number of concurrent connections a browser will make, Chrome for example is <=10 IIRC. You can see this in the waterfall:
`rendering.js`, the last `.js` in the queue, stalled for 300ms.
Additionally, each round trip is dependent on:
- The user's latency
- Your server's response time
So with each connection there is overhead. You would be much better served concatenating these files.
`util.js` took 510ms, of which 288ms was spent stalled (i.e. waiting for a connection) after which spent 220ms waiting (time-to-first-byte).
Furthermore, Lighthouse gives your page a performance score of 60, which isn't great. Key metrics:
- 1.7 seconds to paint (which is okay)
- 7.7 seconds to interactive (which is terrible)
Finally, why on earth are you redirecting to HTTP after serving an HTTPS response? This makes your page load even slower:
if (window.location.protocol === "https:") {
window.location.href = 'http:' + window.location.href.slice().slice(6);
}In HTTP/2, which our site will switch to soon, the concurrent limit is 100. The world's changed, change with it, and throw away those bundlers.
Either way, you can compare to our direct competitors: https://diep.io https://arras.io
> Finally, why on earth are you redirecting to HTTP after serving an HTTPS response?
This isn't really related to the argument at hand. My app is currently on HTTP for reasons downstream.
Also, there are tools that only bundle npm deps, like Snowpack or Vite. I think those would be perfect for your use case.
I'm on Ubuntu 20.04 using the latest Firefox, if that helps.
EDIT: Seems to load fine in Chromium.