Live data from Hacker News

Streaming HTML out of order without JavaScript

lamplightdev.com

41–50 of 104 posts

Re: Streaming HTML out of order without JavaScript

#41

You could possibly do this using a flexbox? https://developer.mozilla.org/en-US/docs/Web/CSS/order

Flexbox order doesn't affect accessibility tree order, so that's bad for accessibility. DOM order should make semantic sense.

There is a new reading order attribute coming to fix this.

Re: Streaming HTML out of order without JavaScript

#42
post #4

At the core, this seems to be about shadowrootmode=open, a new html feature which already landed in Chromium and Safari: This is and sunny funny renders as: This is funny and sunny So it looks like HTML got a bit of a native template system now. What I have been wanting for decades is a native template system in HTML which supports urls. Similar the the script tag, but which loads html: I always wondered why this was…

can be done using service workers or workbox(abstraction to sw)

Re: Streaming HTML out of order without JavaScript

#44
post #2

This looks very interesting, I was not aware that this was possible natively without JS. What's the browser support like?

Chrome, Edge and Safari since March 2023; Firefox since February 2024.

https://caniuse.com/mdn-html_elements_template_shadowrootmod...

Re: Streaming HTML out of order without JavaScript

#45
Real fun begins when you realize that the streamed content can react to interactions that user submits from the streamed page: form targetted into hidden iframe or any other mean of issuing HTTP request back to the server and handling data it can react to in next streamed chunk. This way you can have for example "CSS only chat" [1], or basically anything, since the chunk with new data can contain style directives hiding the old data…

[1] https://github.com/kkuchta/css-only-chat

Re: Streaming HTML out of order without JavaScript

#47

Neat, but what would be the intended use case for something like this? I can imagine a scenario where one part of the UI may take extra time to load, so you would defer it to let the other parts load first. Is there another reason I'd want this?

I used similar streaming HTML for my RSS reader. When you import subscriptions it can take a while as each feed is fetched so I use streaming HTML to show the progress of each feed as it is imported. This provides meaningful progress updates to the user.

However previously the limitation was that the content needed to be more or less in order (you could use some CSS tricks but they were limited). Using this trick I would be able to render the full list of pending feeds then insert a result as each finishes being fetched.

In fact it seems that for each slot the last element will be used. So you can even create live-updating pages based on this which is really cool. For example imaging you had a score ticker. You could push an update to that region of the page every time the score changes.

I think this is definitely a niche use case, but it is very nice to support this without JS. Of course in all but the simplest use cases JS may still be the right solution. For example if the connection drops for any reason there is no mechanism for showing the user an error, let alone retrying.

Re: Streaming HTML out of order without JavaScript

#48
post #23

Earlier quoted context omitted.

The last example reminds me of the once-proposed html imports feature. It was being pushed by Google back when Polymer was a thing and would've given us actual web components delivered as html documents with full support for html, css, and js just like we use normally. If I remember correctly there were a few issues with the approach that needed to be resolved and nobody stepped up to make it a reality. So instead we…

In the end it was only Firefox who implemented HTML Imports, and Google has gone mad and pushed everything in to Javascript.

They went Golden Hammer on v8.

Re: Streaming HTML out of order without JavaScript

#50
post #4

At the core, this seems to be about shadowrootmode=open, a new html feature which already landed in Chromium and Safari: This is and sunny funny renders as: This is funny and sunny So it looks like HTML got a bit of a native template system now. What I have been wanting for decades is a native template system in HTML which supports urls. Similar the the script tag, but which loads html: I always wondered why this was…

> I always wondered why this was never implemented

Wasn't this in HTTP/1.1 (1997), where you could send chunks to anything that could have a target attribute? (As multipart HTML relied on http chunks, which suffered poor support by the Windows http stack, this quickly vanished and in the 2000s support was stripped from browsers. I think, Chrome was the first to do so. Personal note: I once wrote a chat server, which relied on this technology – and it worked pretty well, outside IE.)

Another way this had been once supported was in Netscape 4.0's layers (1997), which could have a `src` attribute and worked just as you would expect. (However, support for this vanished with the first iterations, about the same time JS-styles were switched to CSS. It had been definitely a feature in the NS 4.0 prerelease versions. Especially the capability to re-link the `src` attribute by JS or by a link target was nice.) NS 4 also featured extended HTML entities, which could render JS expressions in place and also provided a mechanism for conditional comments – so, had we followed that route, HTML would have been already a templating language.

Post reply on HN