Re:Real-time updates without JavaScript
by EgoIncarnate on Tuesday February 06, 2018 @04:02PM
(#16319600)
TLDR: It's a basic chat app. It's using a streaming http connection and css "::before" to reverse the order of new output, so it doesn't need javascript. Interesting hack, but...
Re:Real-time updates without JavaScript
by twiss on Tuesday February 06, 2018 @04:12PM
(#16319752)
The CSS to reverse the order is:
main {
display: flex;
flex-direction: column-reverse;
}
The many ::before <style>s are used to update the connection count.
If you like these kinds of tricks, there's also an "order" CSS property, which lets you give elements any arbitrary order you like (by giving each element a numeric index). This can be useful for implementing sorting functionality, for example.
Re:Real-time updates without JavaScript
by lhorie on Tuesday February 06, 2018 @04:46PM
(#16320158)
I mean, sure, it works just fine if people refrain from doing certain arbitrary things (such as the scripted spamming that's happening as I write this), but that's why the grandparent comment said it was a hack and not a trick that one might want to attempt in production.
Re:Real-time updates without JavaScript
by myfonj on Tuesday February 06, 2018 @05:13PM
(#16320407)
Not necessarily: browsers are pretty good at keeping form elements state across refreshes nowadays, especially Firefox. Cursor position perhaps, but not text.
Re:Real-time updates without JavaScript
by sattoshi on Wednesday February 07, 2018 @08:59AM
(#16324396)
At the bottom it says that it uses JS to not require refreshing after each message. This is not necessary as the form can submit to a frame using the target attribute without refreshing the parent frame.
Re:Real-time updates without JavaScript
by nine_k on Tuesday February 06, 2018 @04:25PM
(#16319932)
This is a funny trick, and known for ages, except the CSS-based re-ordering of the incoming info.
It's probably not practical for a chat app (DOM just grows infinitely), but it's a great way to show progress of a longish-running process with a bare minimum of means.
Re:Real-time updates without JavaScript
by thesandlord on Tuesday February 06, 2018 @04:12PM
(#16319756)
This is a really cool hack. Is the source code available somewhere? I understand how the updates are showing up in my browser (using CSS ::before and never closing the connection), but can't figure out how the post works without refreshing the page. Can't view source because the page never actually finishes returning. I'm probably forgetting something basic.
Re:Real-time updates without JavaScript
by wybiral on Tuesday February 06, 2018 @04:21PM
(#16319869)
The POST requests do refresh the page for the poster. But not for the viewers. For everyone else it just streams the HTML to them using chunked encoding.
It's written in Golang and hosted on a free Heroku instance. I'll probably upload the code somewhere after a bit.
Re:Real-time updates without JavaScript
by wybiral on Tuesday February 06, 2018 @05:07PM
(#16320365)
Thanks. There's a subtle trick where new comments (from streamed updates) have a CSS animation but comments from the page reload don't. It seems to make it feel more seamless.
Re:Real-time updates without JavaScript
by jkarneges on Tuesday February 06, 2018 @04:41PM
(#16320099)
If anyone wants to delegate streaming HTML connections like this, it should be possible with Fanout (https://fanout.io) which supports arbitrary content.
Re:Real-time updates without JavaScript
by netgusto on Tuesday February 06, 2018 @04:02PM
(#16319607)
I guess this works by keeping the connexion alive and streaming packets of data, taking advantage of the browsers capacity to render HTML before the whole source is actually loaded.
Re:Real-time updates without JavaScript
by wybiral on Tuesday February 06, 2018 @04:07PM
(#16319681)
Correct. It's a small Golang server that keeps the connection alive with chunked transfer encoding. From the browser's perspective it's like a really slowly loading page.
The connection count is updated by sending some inline CSS ::before content changes.
Re:Real-time updates without JavaScript
by wybiral on Tuesday February 06, 2018 @05:25PM
(#16320516)
Overloading it was failing. But the spam was too much (it was posting so fast you couldn't read anything). I meant for this to just be a fun example of noscript updates so I'm probably not going to add captcha/IP filtering or anything.
Re:Real-time updates without JavaScript
by quickthrower2 on Tuesday February 06, 2018 @04:23PM
(#16319910)
That's what happens when everyone is anonymous and the text scrolls fast, you can't even have a proper conversation so those types of people leave and you are left with a trollbox.
Re:Real-time updates without JavaScript
by meritt on Tuesday February 06, 2018 @04:28PM
(#16319958)
Keep in mind these are the same people whose comments you're reading on HN and the same people upvoting/downvoting whether or not your contributions are seen. Pure anonymity sucks.
Re:Real-time updates without JavaScript
by fwdpropaganda on Tuesday February 06, 2018 @05:53PM
(#16320724)
> Keep in mind these are the same people whose comments you're reading on HN and the same people upvoting/downvoting whether or not your contributions are seen.
Yeah I'm just starting to realise this. Big disappointment.
If you like these kinds of tricks, there's also an "order" CSS property, which lets you give elements any arbitrary order you like (by giving each element a numeric index). This can be useful for implementing sorting functionality, for example.
http://zesty.ca/chat
(1999)
It's probably not practical for a chat app (DOM just grows infinitely), but it's a great way to show progress of a longish-running process with a bare minimum of means.
It's written in Golang and hosted on a free Heroku instance. I'll probably upload the code somewhere after a bit.
Anyway, it was just a proof of concept. The spam could be blocking using some captcha or registration if necessary.
OP?
The connection count is updated by sending some inline CSS ::before content changes.
People...
Also see John Gabriel's Greater Internet Fuckwad theory: https://www.penny-arcade.com/comic/2004/03/19
Yeah I'm just starting to realise this. Big disappointment.
[1]: https://en.m.wikipedia.org/wiki/Meta_refresh