Hacker News new | ask | show | jobs
by andai 320 days ago
16 years after launch, the JS runtime centered around network requests now supports network requests out of the box.
5 comments

Obviously it supported network requests, the fetch api didn't even exist back then, and XMLHttpRequest which was the standard at the time is insane.
Insane but worked well. At least we could get download progress.
You can get download progress with fetch. You can't get upload progress.

Edit: Actually, you can even get upload progress, but the implementation seems fraught due to scant documentation. You may be better off using XMLHttpRequest for that. I'm going to try a simple implementation now. This has piqued my curiosity.

It took me a couple hours, but I got it working for both uploads and downloads with a nice progress bar. My uploadFile method is about 40 lines of formatted code, and my downloadFile method is about 28 lines. It's pretty simple once you figure it out!

Note that a key detail is that your server (and any intermediate servers, such as a reverse-proxy) must support HTTP/2 or QUIC. I spent much more time on that than the frontend code. In 2025, this isn't a problem for any modern client and hasn't been for a few years. However, that may not be true for your backend depending on how mature your codebase is. For example, Express doesn't support http/2 without another dependency. After fussing with it for a bit I threw it out and just used Fastify instead (built-in http/2 and high-level streaming). So I understand any apprehension/reservations there.

Overall, I'm pretty satisfied knowing that fetch has wide support for easy progress tracking.

can we see a gist?
The thing I'm unsure about is if the streams approach is the same as the xhr one. I've no idea how the xhr one was accomplished or if it was even standards based in terms of impl - so my question is:

Does xhr track if the packet made it to the destination, or only that it was queued to be sent by the OS?

Sniped
Mainly by the fact that all the LLMs were saying it's not possible in addition to GP, and I just couldn't believe that was true...
Nerd
What a strange comment. You could always do network calls. Fetch is an API that has similar semantics across browser and server, using Promises.
tell me you're not a Node.js developer :)
Node always had a lower level http module.