Hacker News new | past | comments | ask | show | jobs | submit login

Huh? How does SPA help here? JSON payloads don't go faster over the wire than html.



JS interacting locally can make a web page be perceived to be faster, even if there's no meaningful content yet. Humans enjoy working with systems that so _something_ as soon as they interact with them and a placeholder/spinner/animation is that exact something. Of course, you don't want any placeholders or animations to go on for too long, but it's good to know that the button you just pressed actually did something and the screen hasn't hung.

Minimal JS pages often have very little direct interaction built in, so they feel blazing fast when the connection is good and the payload is small (HN is a great example) but terribly slow if your internet connection is bad and it's not masking the network delays (again, HN is a great example).

The 2-5s mentioned on Twitter are something else though, perhaps the Hey app is being transferred through a saturated connection in the US or something.


Well, a spinner can be added even into non-SPA applications. So I don’t see how that is an argument for SPA.

I presume you can lie to user by pretending that their change was instantly submitted, while syncing in background. In that case, yes, SPA all the way.


That's not really lying, it's good UX. Optimistic updates feel a lot better than waiting for something to happen.


This varies on how important the action is.

Optimistic updates are great for inconsequential stuff like an HN upvote. The user likely doesn't even want to see an error message if their upvote timed out.

But it definitely is "lying to the user", or better phrased "breaking user expectations". It's just that the user isn't likely to care except for important actions.

For example, imagine applying optimistic update to sending an email. The user would expect to be able to close their laptop after sending an email and seeing the UI transition. It would be catastrophic if the email was never actually sent.

Optimistic updates are best relegated to micro-polish imo. Frankly, I think it's overused especially in combination with autosave UI.


Gmail does this all the time, and it makes me mad. I just sort out some mails to have my empty inbox, and then close the browser tab. And it says that the changes haven't been saved, so I need to deal with the popup, and then close the browser tab again...


Skeleton screens and spinners don't feel faster.


An app with longer usage leans towards SPA. Quick or sporadical stuff, shouldn't be a SPA. The problem is always doing, SPA all the things or Do everything in the backend like if it's 2005


Because the DOM can be updated client-side before the server responds


Surely a JSON payload is almost always going to be considerably smaller than the contents of that payload laid out in an entire HTML document?


It’s not the entire HTML document, it’s piecemeal. As for sizing equivalent data in HTML vs js, I remember reading an investigation that XML and JSON are generally closer than you would expect and that for some data structures, XML is terser.


It's not XML though, it's HTML. HTML with additional nodes for layout, class names, etc.

If you're not invalidating the cached code multiple times per day (which, in fairness, a lot of the stuff from Google, Facebook, etc probably are), an SPA should use less data over time than a comparable server rendered app. The initial outlay is bigger, but once it's cached you only need the raw data as you navigate around.


You're right, but the data can be cached and the views shown optimistically. After the first fetch it should be faster.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: