I’ve written a simple NodeJS code to play with HTML streaming, similar to how Next.js do it, but without React. The code first send the placeholder HTML as a partial HTML fragment, then it stalls the request, and send the <script>
tag which modifies the placeholder.
https://gist.github.com/peat-psuwit/53a0b13dfda8781ac34cf6e66cc92ec0
On Chrome, this exhibit expected result: the text “Loading…” is shown while the HTTP request stalls. Then, after 5 seconds, the script which modifies the word “Loading…” is sent in the same request, and word “Hello, world!” is shown.
However, on Firefox, it simply waits until the whole HTTP request is finished before rending. This means that it simply shows the white page for 5 seconds, and then it skips to “Hello, world!” state.
My understanding is that, as I call res.write()
, NodeJS automatically uses HTTP’s chunked transfer capability to transfer the skeleton, partial HTML code to the browser first, which allows “Loading…” text to be seen. My question is why it doesn’t work with Firefox? Or maybe I’m supposed to do additional thing to make it works, and it works on Chrome by accident?
This is Chrome (Chromium) 124.0.6367.60 and Firefox 124.0.2 on Ubuntu 22.04.