Live data from Hacker News

Single Page Application Is Not a Silver Bullet

blog.bloomca.me

31–40 of 111 posts

Re: Single Page Application Is Not a Silver Bullet

#31
post #5

I've worked on a number of SPA's over the years and I always run into the problem of getting my team to give a shit about performance. "We're not Google," they protest. Frankly for a lot of people it's the trade-off of slow client performance for development velocity. It's much easier to just throw on another state for new functionality than it is to consider what parts of the page can be static and how they can be r…

Surely if you can't produce an SPA with equivalent or better performance than a more traditional architecture then - don't build an SPA.

Or even better use a simpler solution that gives me 80% of the benefits of an SPA: Turbolinks, PJAX, intercooler.js or even a light sprinkling of good old AJAX.

Does anyone remember "progressive enhancement"?

Re: Single Page Application Is Not a Silver Bullet

#32

Not the most compelling list of pros/cons that I have ever seen. In terms of raw performance for content sites, I found hybrid implementations like Gatsby.js to beat most things. Most of the cons of SPAs can be significantly diminished with SSR, proper chunking, and a variety of other modern techniques -- it just gets complicated in a hurry.

What's chunking in this context?

Re: Single Page Application Is Not a Silver Bullet

#33

Tangential question: what is the best practice for handling authentication on a SPA? I have seen JWT being heavily criticized on HN and elsewhere. What is the alternative that still maintains the separation between front- and back-end?

Like anything else it depends. JWTs are still great. Just don’t treat it like a classical session and dump important information in it.

You could also use session like you always have if the SPA is being served by the same server.

Re: Single Page Application Is Not a Silver Bullet

#34
post #32

Not the most compelling list of pros/cons that I have ever seen. In terms of raw performance for content sites, I found hybrid implementations like Gatsby.js to beat most things. Most of the cons of SPAs can be significantly diminished with SSR, proper chunking, and a variety of other modern techniques -- it just gets complicated in a hurry.

What's chunking in this context?

Breaking down your JavaScript bundles into smaller files that contain the code necessary for the route you’re actually going to be viewing once the page is loaded. For other routes, you fetch the necessary code on-demand.

This lessens the CPU power and bandwidth needed to initially load the page.

Re: Single Page Application Is Not a Silver Bullet

#35
post #16

One thing that doesn’t get mentioned is that writing an SPA feels more like programming. Writing jquery feels like idk...not quite like programming.

I'd about say the opposite. Organizing all your jQuery into meaningful classes and keeping the whole thing organized and orchestrated is very much the essence of programming. It's a rare skill (as a trip through many large jQuery code bases reveals). Filling in some templates causing magic to happen behind the scenes on the other hand, not so much. That being said, 1) are we interested in feeling like programmers or…

>I'd about say the opposite.

>Organizing...into meaningful classes and keeping the whole thing...orchestrated is very much the essence of programming

>Filling in some templates causing magic to happen behind the scenes on the other hand, not so much.

I'd agree and add that the different perspectives might be in large part due to the shift in programming away from procedural/code to declarative over the last decade or so. That is, if you started in coding over the last ten--and especially five years--you're much more likely to think of programming as declarative as much as code-oriented.

And, the shift towards frameworks is probably the biggest driver of the declarative trend itself.

Re: Single Page Application Is Not a Silver Bullet

#37

I always thought the decision was: - Content site = NOT single-page-app - Application = single-page-app Maybe there's more of a gray area between content sites and applications these days, but I think it's still pretty obvious: If most of the user's time is spent reading content, it's a content site.

The problem is even content is becoming functional with interactive charts, infographics and figures, videos, media, filtering, sorting - then the site will eventually need comments, ads, subscribing, favoriting, upvoting, login, lazy load next article, infinite scroll, etc. Yes, a pure content site shouldn't be an spa, but how long can you survive running a pure content site? Information is complex and the web allow…

What are static 2d representations?

You can do everything you mentioned without an spa just fine. Plenty of content sites (the majority, actually) survive just fine.

Re: Single Page Application Is Not a Silver Bullet

#38
post #16

Earlier quoted context omitted.

I'd about say the opposite. Organizing all your jQuery into meaningful classes and keeping the whole thing organized and orchestrated is very much the essence of programming. It's a rare skill (as a trip through many large jQuery code bases reveals). Filling in some templates causing magic to happen behind the scenes on the other hand, not so much. That being said, 1) are we interested in feeling like programmers or…

> I'd about say the opposite. > Organizing...into meaningful classes and keeping the whole thing...orchestrated is very much the essence of programming > Filling in some templates causing magic to happen behind the scenes on the other hand, not so much. I'd agree and add that the different perspectives might be in large part due to the shift in programming away from procedural/code to declarative over the last decade…

lol you caught me, I'm old.

I'm all in favor of what's fast and easy. So many jQuery messes have almost given me PTSD. So not knocking frameworks in any way. It's just weird to me someone would suggest using them is "more like real programming". No, it's more like one of those paint by number kits rather than a blank canvas and some paint. Of course many people are going to get better results with the paint by number kit, but it isn't more like "real" painting. It's less like "real" painting. And, if you reach for a paint by number kit when all that's needed is a few red dots you are messing up and ought to learn the craft naked a bit for such situations. jQuery isn't a paint by number kit. More a set of stencils and brushes you are free to make as big of a mess as you like with.

Re: Single Page Application Is Not a Silver Bullet

#39

Tangential question: what is the best practice for handling authentication on a SPA? I have seen JWT being heavily criticized on HN and elsewhere. What is the alternative that still maintains the separation between front- and back-end?

Tangential answer: It would vary based on sensitivity of your application. JWT is not a bad option if we do not have a requirement of absolute session termination and if implementation does not have any vulnerability. People also use cookie shared on the root domain(backend and front end can be served by different sub domain. Also you can use custom headers since cookie is just another type of header managed by browser itself. The additional work would be around managing the additional header on back end. People generally open doors for CSRF attack by separating front end and backend like this. Good thing is that there are simple solutions to mitigate that risk too.

Re: Single Page Application Is Not a Silver Bullet

#40
This might not be a popular opinion here, but yes, SPAs are indeed a silver bullet.

Or at least, no you shouldn't make a site that isn't SPA. With universal rendering, light frameworks like Preact/Inferno.js and things like microjs.com , you can make a site that loads faster, renders faster and navigates faster then a multi-page application. You can make SPAs behave like a regular site - with links that work and all.

It's simply that many developers/managers don't care for or know how to make fast websites with SPAs, but then again even Multi-page applications are usually bloated with dozens of marketing, analytics and third-party libraries which makes them just as slow.

I don't think reloading the entire page on every request is acceptable in 2018, even if it's a blog.

Post reply on HN