← Back to context

Comment by lelanthran

2 days ago

> don't know if they fixed it, but when reddit rewrote their menu with web components, it required 100+ http requests to render.

Nothing to fix, mostly. Those are static requests and get cached.

Or you do a single request with a sane framework, and it gets cached.

It's a menu, not a nuclear plant dashboard.

  • I have a wrapper around fetch for static requests so that no matter how many requests for the same file are made at the same time, only one of them actually goes out over the wire.

    There is no problem here, whether you have a page that requests a static file 1000 times in a nested DOM or a single time. The outcome is still only a single request.

    • > I have a wrapper around fetch for static requests

      imports are not fetched by JS fetch. They are fetched by the browser. It happens before any JS in the component is even run.

      That's why web components force request cascades: for every import the browser fetches the script, parses it, and starts fetching imports there, recursively.

      Edit: it's also one of the reasons why bundling exists in most JS build tools. `import` was conceived when parallel fetching over http2 was right around the corner... and never materialized. So why make potentially hundreds of inneficient network calls (with browsers restricting them to something like 4 at a time), when you can just collocate code and dependencies?

      4 replies →