Hacker News new | past | comments | ask | show | jobs | submit login

> 1. How do you handle npm dependencies that don't expose ES modules?

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.io

For a small performance boost, you can load smaller files first via <link rel=preload>.




This is terrible advice.

> 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);
    }


> 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:

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.


Thanks for the response, but IMO both of those solutions are strictly worse than having a build step that takes care of it.

Also, there are tools that only bundle npm deps, like Snowpack or Vite. I think those would be perfect for your use case.


Hi, I tried accessing your site, but seems like it's stuck in this weird reload loop. It never full loads.

I'm on Ubuntu 20.04 using the latest Firefox, if that helps.

EDIT: Seems to load fine in Chromium.


You probably have HTTPS Everywhere with EASE mode on.


Why wouldn't the site have HTTPS enabled?


An artistic or deeply philosophical choice by the author that, in order to view their work, you must permit yourself to be man-in-the-middled?


Mixed Content: HTTPS sites cannot connect to HTTP resources. The game needs to dynamically scale without expensive load balancers in front. Until I get dynamic DNS and HTTPS working, the site will not have HTTPS.


Thanks, the issue was Firefox's built-in "Enable HTTPS-Only Mode".


So your solution to build systems has absolutely none of the benefits that build system do in fact bring, or the ecosystem of a language that you might consider terrible but actually has a decent amount of quality re-useable code. But this works for your very specific use-case?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: