News for hackers. Stuff that matters.
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 The_suffocated on Tuesday February 06, 2018 @04:06PM (#16319662)
But what?
Re:Real-time updates without JavaScript by lhorie on Tuesday February 06, 2018 @04:10PM (#16319727)
It breaks when you press `esc`. Either that, or the DOM just keeps growing and hogging memory until the tab eventually becomes unresponsive or crashes
Re:Real-time updates without JavaScript by The_suffocated on Tuesday February 06, 2018 @04:14PM (#16319776)
Thanks, but isn't this the same if you use a virtual DOM? Is Mithril not prone to this problem if you keep adding stuffs to the list?
Re:Real-time updates without JavaScript by lhorie on Tuesday February 06, 2018 @04:17PM (#16319820)
With javascript you can keep an EventSource connection open (which is immune to the `esc` thing), and you can prune the DOM and let the browser GC.
Re:Real-time updates without JavaScript by The_suffocated on Tuesday February 06, 2018 @04:28PM (#16319956)
Thanks for the explanation. I'm too green to understand this, but I'll try to learn more about it later.
Re:Real-time updates without JavaScript by wybiral on Tuesday February 06, 2018 @04:37PM (#16320065)
Presumably you'll eventually write something rather than lurking for hours and then it'll refresh.
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 wybiral on Tuesday February 06, 2018 @05:32PM (#16320563)
The spam had nothing to do with not using Javascript. I could easily have added a CAPTCHA or required accounts.
Re:Real-time updates without JavaScript by roywiggins on Tuesday February 06, 2018 @04:39PM (#16320081)
In extremis a <meta refresh> could be used.
Re:Real-time updates without JavaScript by reificator on Tuesday February 06, 2018 @04:49PM (#16320187)
But then if you refresh every ten minutes or so, and I just happen to be finally responding after that long, I'm going to lose what I'm typing.
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 reificator on Tuesday February 06, 2018 @09:52PM (#16321909)
Perhaps, but certainly there will be frustration there. Especially WRT cursor position changing.
Re:Real-time updates without JavaScript by sebazzz on Tuesday February 06, 2018 @05:02PM (#16320321)
My Surface tablet got warmer and warmer on my lap.
Re:Real-time updates without JavaScript by ErunamoJAZZ on Tuesday February 06, 2018 @04:09PM (#16319708)
Page never end to load.
Re:Real-time updates without JavaScript by zestyping on Tuesday February 06, 2018 @04:24PM (#16319923)
If you liked that, you might also enjoy this little hack. How about real-time updates without JavaScript or CSS tricks?

http://zesty.ca/chat

(1999)

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 thesandlord on Tuesday February 06, 2018 @04:41PM (#16320104)
Oh wow, I couldn't really notice the page refreshing at all... Nice job.
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 Felk on Tuesday February 06, 2018 @04:19PM (#16319846)
You're forgetting about F12 :)
Re:Real-time updates without JavaScript by The_suffocated on Tuesday February 06, 2018 @04:08PM (#16319699)
Thanks for the demonstration. I didn't know this chunked encoding technique before.
Re:Real-time updates without JavaScript by wybiral on Tuesday February 06, 2018 @04:40PM (#16320093)
It's being flooded with spam now. This is why we can't have nice things.

Anyway, it was just a proof of concept. The spam could be blocking using some captcha or registration if necessary.

Re:Real-time updates without JavaScript by pedalpete on Tuesday February 06, 2018 @04:30PM (#16319990)
Compared to using a socket server, how many connections can this server maintain?
Re:Real-time updates without JavaScript by teraflop on Tuesday February 06, 2018 @04:34PM (#16320031)
Presumably the exact same number. A TCP connection is a TCP connection.
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.

OP?

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 mcdirty on Tuesday February 06, 2018 @05:23PM (#16320500)
And someone wrote a script to overload it. ~Nice Try~ :D
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.

People...

Re:Real-time updates without JavaScript by MattPearce on Tuesday February 06, 2018 @04:53PM (#16320222)
Also no filtering, you can just chuck raw HTML in there
Re:Real-time updates without JavaScript by wybiral on Tuesday February 06, 2018 @05:05PM (#16320348)
That's not true. I allowed b, u, i for a while but people kept not closing them so even those are disabled.
Re:Real-time updates without JavaScript by petagonoral on Tuesday February 06, 2018 @05:57PM (#16320747)
interesting that neither chrome or firefox network dev tools can/will show a response for the 'GET' request
Re:Real-time updates without JavaScript by dustinsterk on Tuesday February 06, 2018 @05:24PM (#16320511)
Never can have nice things......
Re:Real-time updates without JavaScript by fwdpropaganda on Tuesday February 06, 2018 @04:18PM (#16319831)
What's with the shitty people? "Europeans are useless", "fuck white people", "fuck black people" etc. Ludicrous.
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.

Also see John Gabriel's Greater Internet Fuckwad theory: https://www.penny-arcade.com/comic/2004/03/19

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.

Re:Real-time updates without JavaScript by chc on Tuesday February 06, 2018 @05:04PM (#16320339)
This is partially alleviated by the fact that you can't downvote until you reach a certain karma threshold.
Re:Real-time updates without JavaScript by tannhaeuser on Tuesday February 06, 2018 @04:24PM (#16319911)
Meta refresh has been used with WebCams for ages.

[1]: https://en.m.wikipedia.org/wiki/Meta_refresh

Re:Real-time updates without JavaScript by wybiral on Tuesday February 06, 2018 @04:28PM (#16319961)
It's not using meta refresh. The content is streaming.