Imagine a few customers open up your site and leave for lunch. Or maybe just a random crawler or bot sitting watching for some piece of information they are scraping.
These sorts of issues can be challenging with stateless connections. I can only imagine how daunting they are with persistent connections.
Games basically do this routinely.
What happens if a webpage is loaded over plain old HTTP and then over lunch a breaking change is deployed. The page the user loaded before lunch is now no longer compatible.
It’s stateless. If the api changes from underneath and you’re polling or something, then just show an error, have the user refresh the page and move on. Or use any of the various api version mechanisms for backward compatibility. It’s not an easy problem but it’s a fairly well understood and managed one. Solving this kind of known problem isn’t, to me, a very compelling case for HTML over sockets.
With server-fed, event-driven pages, you could potentially force refresh.
I assume web-sockets could make it work more robustly.
A crash or someone hitting refresh on his browser is not that different in this respect.
WSs aren't a magic wand, they just allow you to do more with the same.
You basically end up with a half-assed, buggy, and potentially insecure reimplementation of HTTP running over web sockets running over HTTP at that point.
Are you going to do session management and identification by issuing a unique identifier as well? Is that unique identifier going to be valid in perpetuity or have a an expiry date? Is it going to be valid and secure across all sub-domains or will it be prone to cross site scripting attacks?
The purpose is in the things explained well in TFA: single source of truth, no replicated state, simpler development, and so on...
Who said the purpose would/had to be in handing "the server caught fire" scenarios?
It works for certain things and not for others. So, it's not "the future of web software" like the title says, it's one additional possibility for when it makes sense.
Because you can do things stateless HTML alone cannot do.
No one is trying to re-implement HTTP, or even remove it from the equation.
What people are trying to reimplement (or rather, replace) is the HTML + JSON:API + React + Redux mess. Websockets is a means to that end.
Unfortunately, great intentions alone won’t make this work; someone has to actually answer the hard questions about how it’s going to work too.
All the answers I’ve seen so far trying to answer them have been vague hand waving...
That doesn’t leave me with much confidence.
People did better than that, they already built applications with this model.
Here is the documentation for Phoenix channel authentication (what Phoenix Live View is built upon): https://hexdocs.pm/phoenix/channels.html#using-token-authent...
Additionally, here is some documentation on the security considerations specific to Live View: https://hexdocs.pm/phoenix_live_view/security-model.html
Searching can probably find you more information.
I should probably already know this.
HTTP is quite literally "hypertext over sockets" so "HTML over websockets" is functionally equivalent... with a layer of abstraction added on top. If you build web software by sending HTML over websockets you're just reinventing what already exists; it's probably why it's never taken off. I think most developers realize within ~weeks to months of working on a "websocket-everything" framework that they're doing more work, not less.
Why would you? Nobody seems to ensure that with regular SPAs anyway...
- What happens if the client’s internet connection temporarily drops? How do you handle client reconnections and retries?
- What if the remote server crashes through no fault of your own (AWS server rack catches fire)? How do you ensure a consistent reconnection that preserves application state?
These are just two questions that HTTP + Browsers solved decades ago.
Websockets are this cool technology that seems powerful and exciting until you realize the “boring old stateless World Wide Web” was built over decades of iteration using stateful sockets as the backbone, did most of the work for you in tandem with browsers, and is ultimately a lot cooler and more sophisticated than a lot of us give it credit for.