10 ms·
Stupid solutions: Live server push without JS
- allanrbo 6y agoHe mentioned chunk streaming text in an iframe I think as a joke, but I remember actually implementing a decent chat web app exactly like that years ago in the IE5 days or so.
- robertlagrant 6y agoYeah you basically never close the response, right? Just keep appending! Chat is a good use case for it. Maybe with CSS these days you could make only the last child of a div visible, and have constant updates with no need for JS. Anyway. I quite like this idea of no JS. I know he said it would be evil to serve ads using MJPEG, but I'd probably prefer it if my page had less JS on it.
- lukeramsden 6y ago> Anyway. I quite like this idea of no JS. I know he said it would be evil to serve ads using MJPEG, but I'd probably prefer it if my page had less JS on it. Honestly I don't see how it's more evil, just because it doesn't use JS surely doesn't mean uBlock and such can't still block it? To be evil all ads full stop would have to be evil. As you say, I would much prefer this to ads that use JavaScript. If you can still show me ads on your news article when I haven't got JS enabled I'm not going to be too bothered, because hopefully everything should load plenty fast. It also means the rest of the site can load while the ads are loading.
- ks 6y agoA company I worked for in 2001 used chucked streaming to provide search results. The search results were collected by performing live searches in parallel (server side) with multiple partners and then aggregated into a single stream of chunked content. Basically the HTTP connection was kept open until all searches were complete, which would take a few minutes. The results were pushed incrementally to the browser as soon as they were available This worked surprisingly well. They started with almost pure HTML with the results split into multiple tables to produce what looked like a single table of results. The only drawback was that the columns needed fixed width so that they would align properly. After a while they switched to a Javascript based solution with dynamic filters. They used the same backend streaming engine to output chunks of Javascript code inside <script>-tags, which called a global "addResult(...)" method to update the state. If the search was cached, it would first render HTML code server side, which was then "hydrated" by the javascript code if needed. Later it was replaced with a standard XHR polling mechanism. It is interesting to look back at what we had to do that is trivial with today's technology.
- alex_duf 6y agoYep, I've done that to send the status of a large upload, that must have been around 2008 or so. We had a progress bar that would show the upload percentage, then the unzipping, then the virus scan on the server, then it would be marked as done.
- finiteloop 6y agoAt FriendFeed, when we first introduced real-time comments and likes (pretty sure we were the first social network to do this), we did it with long-polling via an iFrame because web sockets did not exist. It actually worked pretty well! https://www.ft.com/content/87b8107e-9c6d-3d3f-a60d-3e4f6315d02e https://www.ft.com/content/87b8107e-9c6d-3d3f-a60d-3e4f6315d...
- nudpiedo 6y agoI have the feeling that as soon as the web got obsessed with HTTP(s) only transactions between nodes, people reinvented/rediscovered/hack-reimplemented socket's semantics on top of it.
- necovek 6y agoIt's hard for the web to become "obsessed with HTTP", because web is HTTP. Pedantry aside, as soon as web/HTTP became The Internet (protocol of choice), you are right that the rest was bound to happen. However, exactly the fact that it wasn't too constrained and allowed a lot of messing around (including with HTML, compared to eg gopher which was more semantic) is what made it "win" over all the other protocols except maybe email (and even there, >50% of people read it with web clients).
- lgessler 6y agoI think GP's talking not just about server-client connections but also server-server connections? In the latter case HTTP(S) wasn't as popular as it is today until the late aughts.
- nudpiedo 6y agoI was speaking about the web as a net-work (not just web as in HTTP webpages). There are other protocols such as FTP, SMTP, and direct socket connections over TCP and UDP, but many of these use cases were absorved by REST only (HTTP) transactions and now websockets.
- necovek 6y agoThat's exactly the misconception I was trying to correct, assuming you made it while understanding the difference. That suite of protocols is a suite of internet protocols, and "web" (from "world wide web", certainly familiar from www in websites) is a combination of HTML served over HTTP. If it has evolved to mean the internet, my apologies, but 10-20 years ago if you said "web", you meant HTTP: https://en.m.wikipedia.org/wiki/World_Wide_Web https://en.m.wikipedia.org/wiki/World_Wide_Web
- arraypad 6y agoThe core of this is of course the response header "Content-Type: multipart/x-mixed-replace" which in theory lets the server push updated chunks of any content type (although apparently only images in Chrome since 2013 [1]). While it's a crude and handy way to update some content after the initial load without JS, it was also widely used with JS before Web Sockets - to push messages to clients with less latency than XHR polling. [1] https://en.wikipedia.org/wiki/Multipart/x-mixed-replace#Mixed-Replace https://en.wikipedia.org/wiki/Multipart/x-mixed-replace#Mixe...
- pronoiac 6y agoomg! I thought it would slowly create and send along an mjpeg video file. Server push animation is a 90's thing. I wrote something up about it in 2009, and posted a still-working demo, because of a thread here. https://pronoiac.org/misc/2009/10/server-push-animation/ https://pronoiac.org/misc/2009/10/server-push-animation/
- bullen 6y agoThe big problem with this spec (which is shared today by all the HTTP uploads in the world) is that you have to check for the delimiter every byte! "Content-Type: chunked" is much better because it gives you the size of each chunk upfront! But that requires .js and also was buggy in IE until version 7. I made a multiplayer online system that relies on chunked: https://github.com/tinspin/fuse https://github.com/tinspin/fuse
- jswrenn 6y ago> although apparently only images in Chrome since 2013 I wonder if this includes SVG images... EDIT: It does!
- bawolff 6y agoWhy not just stream a normal video stream?
- egil 6y agomjpeg is a normal, albeit very simple video stream. While you could certainly squeeze the counter in less bytes by using a more advanced codec with interframe coding, it would be overkill for this poc.
- bawolff 6y agoThe point im trying to make is more that video streaming is a standard technique with off the shelf solution. The author presents MJPEG as some long lost solution to do this without js, but you can just as easily throw in a <video> tag without JS and call it a day. Except video tags arent as exciting.
- lawik 6y agoApparently HLS (HTTP Live Streaming) requires JS on every platform aside from Apple's. I was looking at that for streaming video + captions but since it requires JS to run it didn't really achieve what I wanted it to. Maybe you could build an in-memory video stream for each user and just serve it slowly but then they would likely need to press play or you rely on autoplay and I've no idea how well that would play with buffering behaviour. This solution maps quite closely to the idea that MJPEG is intended for "live" video. And also I find it adorable that it is just an img tag.
- shakna 6y agoAlmost every browser accepts, and sends, byte-range headers for video, which is pretty easy to map for an endless stream - you don't have to return the actual length of the video, and if you don't, browsers will treat it as an endless stream. Whilst you do have to actually trigger the play somehow, the range will come in controllable chunks, so you can respond in kind without trashing the stream.
- 6y ago
- browserface 6y agoI use MJPEG to livestream headless chrome[1]. You can set it up to use the HTTP endpoint but I just do it over WebSocket. [1]: https://github.com/dosyago/OuterShell https://github.com/dosyago/OuterShell
- koliber 6y agoThere are a few other ways: - dynamically generated animated GIFs - Content-Type: multipart/x-mixed-replace : the way to animate images on the web since 1993 - before animated GIFs
- reaperducer 6y agosince 1993 - before animated GIFs* Animated GIFs have been around since 1987.
- reimertz 6y agoThis is so cool and very similar to a hack I did some time ago: Noscript-compatible twitch-plays-Zelda http://nes-o-png.herokuapp.com http://nes-o-png.herokuapp.com So crazy what you can do with server-side-rendering if you really want to. :)
- notRobot 6y agoSo now we know that a #1 post on HN has about ~450 concurrent visitors Edit° (~1 hour later): So I've been checking every few minutes, and it's consistently been at ~450, this is a cool metric to have. °This link was posted to HN ~4 hours ago. I first checked ~1.5 hours after it'd been posted, and it was #1 on the front page. It's still #1 as of this edit. The counter has consistently been between 445 and 455 the whole time.
- richrichardsson 6y agoWhen the Europeans are coming up for midday at least. I wonder how that number will change depending on who's up.
- browserface 6y agoAnd... It crashed. Image is currently down.
- lawik 6y agoThe counter does go up and down a bit. I'll have to check the logs and see what that's about at some point. Mostly it comes back up on refresh.
- notRobot 6y agoUpdate: now it's on #2, and it's hovering around 430
- notRobot 6y agoUpdate: #3 and ~130. Whoa, dramatic fall. Edit: #4, post is six hours old, counter up to ~190. Edit: #5, ~6 hours, 173 points, ~220 current site readers. Edit: Back to #4, ~6 hours, 186 points, ~300 site readers.
- lawik 6y agoDramatic fall was Nginx config bump and restart. Lost all those sweet idlers I'm sure. Hopefully it can go higher now with some luck but we might be past the peak. Really curious how far it can manage.
- donatj 6y agoI made a little nojs shared drawing board a few years back that worked with MJPEG as the background of an image button ‘<input type="image" ...>’. Clicking the image button submits the form with x and y click coordinates, and the server returns an HTTP 204 telling it to stay where it is, followed by pushing out the updated jpeg to all connected clients. It’s pretty fun, and I wanted to have it online all the time but it has a problem I haven’t sorted out where sometimes when a client disconnects the server won’t realize and trying to push them a jpeg locks the whole rendering system. https://github.com/donatj/imgboard https://github.com/donatj/imgboard
- lawik 6y ago204 you say. Please don't make this rabbit hole deeper for me :)
- donatj 6y ago204 is a wonderful rabbit hole! You can use it to send messages to the server without refreshing the page without JS. It was a pretty common trick in the early 2000s
- dsego 6y agoHow do you detect a success/failure without JS?
- donatj 6y agoSend an actual error page rather than a 204. It's not perfect, but in cases where the server returning an error is very rare, it's fine. Since there is no state anyway, the user hitting back is fine. Most JS apps in my experiences fail to handle server errors with any sort of user feedback at all.
- forgotmypw17 6y agoThank you very much for sharing this. I'm attempting to support every client in every configuration on my web-based forum, and this would be a nice little toy.
- 0-O-0 6y ago> this can be used for evilish things. You can absolutely keep track of how long someone keeps receiving your frames and use that for your analytics There is nothing evil in analytics by itself - it's invaluable for improving usability.
- stanislavb 6y agoIn the light of this post, I'd like to share that I made an almost "no js" live monitoring service a few days ago. Again with the help of Elixir (and Phoenix LiveView). It tracks everything that's posted on Hacker News and Reddit in "real-time", and distributes it to everyone listening to it. And it tracks the number of online users, too. Of course. You can check it out here https://alertcamp.com/live/Apple,Google,Microsoft,Amazon,Facebook https://alertcamp.com/live/Apple,Google,Microsoft,Amazon,Fac...
- bdcravens 6y agoI think by "no js" it's not whether you write JS, but whether the page uses it. LiveView relies on WebSockets and Javascript.
- lawik 6y agoWhen I posted this in another context someone linked this beauty: https://github.com/kkuchta/css-only-chat https://github.com/kkuchta/css-only-chat
- fishtoaster 6y agoHey, that's mine! But yeah, it includes an alternate approach to the same problem: use http chunked encoding and continually append html to the web page (which never quite finishes loading). Funnily enough, it also uses another evil trick with css background images, which TFA mentions as well: https://underjord.io/is-this-evil.html https://underjord.io/is-this-evil.html
- draw_down 6y agoWell sure, it doesn’t do this, or this, nor this either, and it’s hacky and not accessible, but at least it doesn’t use JS!!! Good grief.
- leephillips 6y agoThis is great to know about. But on qutebrowser (QT webengine) it doesn't update. When I tried it on Google Chrome, it worked as expected. So maybe not as universal as the author believes.
- The-Compiler 6y agoWorks for me. Perhaps you're using an older Qt version?
- leephillips 6y agoHmm. I’ll have to check that, thank you.
- Ensorceled 6y agoQuite a few people are having trouble groking the "stupid solutions" part.
- baud147258 6y ago> a fun hack that simply happens to work across browsers Didn't work on IE. But still something really interesting
- icedchai 6y agoWhy not an iframe with a meta refresh tag? That seems more standard than rendering text using a video stream. Sure, it's not "live" but an update every second or so would be good enough for this use case.
- pmontra 6y agoThat's what we were using before XHR in IE5 (it had another name but same stuff.)
- renewiltord 6y agoI think I've seen this done with an infinite animated GIF as well.
- feniv 6y agoSeems like an interesting variant of SSE (Server sent events) without the JS code for retries. Both of these approaches are simpler than websockets, with the limitation that they're one-way (server push).