TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Single Page Application Is Not a Silver Bullet

196 pointsby bloomcaover 7 years ago

35 comments

vincentriemerover 7 years ago
As an avid developer of SPAs (currently working on one for my own blog frontend) I&#x27;d say a lot if this stems from people being convinced SPAs 1) provide a faster development cycle, 2) they believe that they&#x27;ve offloaded all need for optimization on the framework they use and 3) &quot;serious&quot; development teams build SPAs.<p>Anecdotally I find SPAs, while I&#x27;m more comfortable developing them, will take longer to build. You need to pay more attention to the quirks the author mentions and you need to spend more time explicitly optimizing your code. I like this paradigm because if there is inconsistent logic, poor performance, or other issues, it&#x27;s my fault and I have the opportunity to fix it.<p>As a counter example to the ones mentioned in the above article, around 2 years ago I build a drum machine webapp entirely in JavaScript&#x2F;React (<a href="https:&#x2F;&#x2F;io808.com" rel="nofollow">https:&#x2F;&#x2F;io808.com</a>). This has ~17 JS library dependencies and ~6000 lines of source code but the gzipped bundle size comes out to ~97 KB.<p>Just because you&#x27;re building an SPA doesn&#x27;t mean you need to spend less time optimizing your code, in fact it likely means the opposite.
评论 #16304504 未加载
评论 #16305087 未加载
评论 #16305556 未加载
andrenotgiantover 7 years ago
I always thought the decision was:<p>- Content site = NOT single-page-app<p>- Application = single-page-app<p>Maybe there&#x27;s more of a gray area between content sites and applications these days, but I think it&#x27;s still pretty obvious: If most of the user&#x27;s time is spent reading content, it&#x27;s a content site.
评论 #16304138 未加载
评论 #16303857 未加载
评论 #16304210 未加载
评论 #16307619 未加载
burlesonaover 7 years ago
One of the ways that I prefer to judge a JavaScript framework is (1) what is the minimum payload to use it, and (2) how nicely does it play with a hybrid app?<p>In practice I’ve found VueJS does pretty well in this regard. Rather than build a full SPA I can sprinkle a few components here and there on pages that are highly interactive. The rest of the mostly static screens on my app are perfectly happy to be rendered from the server.<p>It can be hard to strike the right balance between developer friendliness (ie maintainability and extensibility) versus user experience (ie speed and backwards compatibility) these days, but as always it’s important work to deliver the best user experience we can, and I agree with the author that SPA are not always the right choice in this regard.
评论 #16304174 未加载
baddoxover 7 years ago
&gt; broken “open in a new tab” behaviour – people like to handle links in onClick handler, and browser can’t recognize it as a link (even if the majority of the links are valid, sooner or later you’ll encounter a non-link “link”)<p>This one annoys me the most, but I will say an analogous problem is fairly common on non-SPA web sites, where reloading a URL doesn’t work as expected.
评论 #16303819 未加载
JohnnyCrazyover 7 years ago
TBH most of the cons stated in this article are just because of bad programming, not because it&#x27;s a SPA<p>&gt; broken “back” button (sometimes it works properly, but in general people don’t trust it)<p>If your UX is good, the user will notice data is refreshed when going back. All current top tier SPA Frameworks have support for correct HTML5 routing.<p>&gt; broken “open in a new tab” behaviour – people like to handle links in onClick handler, and browser can’t recognize it as a link (even if the majority of the links are valid, sooner or later you’ll encounter a non-link “link”)<p>Again, most up-to-date frameworks have a fallback by adding a normal href so you can still CTRL-Click it.<p>&gt; sometimes broken “refresh” button – after refreshing you end up in a different UI (usually slightly, but still different)<p>I don&#x27;t see a real disadvantage here, since you can simply store your state by manipulating the URL or even localstorage. So you even have the possibility to not store your state...But again, application design, not SPA<p>I do agree with TTI (at least on the first load) and bad performance on low end devices.
评论 #16303948 未加载
评论 #16304696 未加载
userbinatorover 7 years ago
Half-expecting this article to itself be SPA, and was pleasantly surprised that it isn&#x27;t.<p>I agree completely with the author; there&#x27;s some things (games and such come to mind) which certainly deserve to be SPAs, but the majority of the time it&#x27;s a horrific waste for every single visitor to have to process MBs of data just to display a few KB of text and hundreds of KB of images (at most). Why? Just so developers can show off that feeling of how awesome they are for using some incredibly complex framework. That, and the ridiculous rate of churn, are probably what most irks me the most about the whole web development community (and why sites like HN appeal to me so much.)<p>I&#x27;m not sure what&#x27;s responsible for this &quot;love of bloat&quot;, but IMHO we should be teaching developers how to do more with less, and not the complete opposite as seemingly happening today.
评论 #16304557 未加载
photoniosover 7 years ago
Some of the arguments the author mentions are not really good arguments. Basically it boils down to how much you care about the user experience. I designed and developed a SPA for a large real-estate portal in &lt;6 months. I think we&#x27;ve nailed all of the points the author mentioned:<p>- Initial request is rendered server-side, so TTI is extremely low. Even if the JS hasn&#x27;t kicked in, the website is already usable.<p>- Back button works perfectly fine. We use the HTML5 `history.pushState` method to add new entries to the history stack.<p>- Links are always rendered as anchor tags. So even if the onClick handler fails or the JS crashed, the link will still work.<p>- Compress the hell out of the bundle. Clocking in at 190KB compressed. (Edit: should do something about this, should be &lt;100KB)<p>Basically, we have most of the advantages of rendering &quot;static&quot; pages, yet also get all of the advantages of an SPA. We can do pre-loading in search results for example. If you click a link in search results, we immediately render the page and use the data from the search result to show a basic page and then slowly enhance it.<p>This powers a large real-estate website that receives hundreds of thousands of visits a week. For this kind of business, a lot of stuff is important to get right. SEO related optimisations are extremely important. Hence, we server-side render everything to make sure the GoogleBot can read it all. The same applies to links. We keep our bundle size as small as possible to keep things speedy.<p>Oh, and I personally got a kick out of spending a weekend to make the website function perfectly well without JS.
评论 #16305191 未加载
thehardsphereover 7 years ago
The problem with SPAs in the sort of cases that the author is talking about is that people don&#x27;t think clearly about what requirements they are satisfying when writing a new one. If your app actually needs to switch between various screens without a refresh so your users can most efficiently get their work done, then yes, by all means, make an SPA. That requires knowing clearly who your users are, what they want to do, and what constraints they are under (e.g. if they all work on desktops with good internet access, maybe it doesn&#x27;t matter that your app is bloated and slow on mobile). I think most people don&#x27;t do that thinking step first. They want to play with the new shiny, either as a sort of fun or so they can add it to their resume.<p>This I think is made worse by the unparalleled decadence in which the modern, first-world developer now lives. It is absolutely excessive to have to download 2.6 MB just to show a blog or some simple textual information, but thanks to broadband everywhere and terabyte hard drives, nobody under the age of 30 who isn&#x27;t working in embedded systems thinks about this anymore.
nikkwongover 7 years ago
From a development perspective, in my humble opinion the single biggest hurdle with developing SPAs vs traditional server side applications are problems dealing with state consistency. The state model in non-spa apps is simple: when a pageload is requested, pull the latest state from the server. In SPAs the state has to be held on the client and server, and has to be able to react to state changes from the other side of the wire.<p>Also I think that large bundle size being a mark against all SPAs is misleading. Yeah, angular is 1mb+, but vue is ~20kb, so the potential for the bundle to be small exists.
评论 #16304823 未加载
buzz27over 7 years ago
I was thinking about this recently watching a major web app throw a bunch of errors and slowdownsall to do with its SPA features. If it was just a normal web app it would be so much faster and more usable. It seems crazy to me that we have faster and faster computers and internet connections, and yet we&#x27;ve added all this new latency to the software we use.<p>I find the list of pros somewhat unconvincing.<p>For a lot of applications, a reload is no hardship, and is faster than most SPA interactions I see.<p>For a lot of granualar actions, jquery, while not sexy, is not harder to maintain than a full SPA would be.<p>The alleged development efficiency of decoupling front from back really needs context and argument.<p>As I see things, there are a lot of web projects where a normal app with a little progressive enhancement is a good solution.
sebringjover 7 years ago
I thought gatsbyjs was a nice medium ground. You have the familiarity of a single-page app in terms of stack and yet have the quick loading times and back button, SEO all of that since it produces a static site. I thought it was genius but I&#x27;m biased because I like react.
评论 #16304444 未加载
评论 #16304439 未加载
eadmundover 7 years ago
I recently started blogging again, and I chose to go with a static site generator. It&#x27;s <i>fast</i>, really fast. Loading a whole page with each click is so much faster than visiting most of the sites I visit each day.<p>I&#x27;ll never get why we collectively decided that it&#x27;s reasonable to grant every random website in the world execute permissions on our machines.
buchanafover 7 years ago
Not the most compelling list of pros&#x2F;cons that I have ever seen.<p>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.
评论 #16304187 未加载
评论 #16304224 未加载
scarface74over 7 years ago
I have mixed feelings about SPAs. I&#x27;m mostly a back end developer but do have some front end experience. On one hand, I think life is a lot simpler with server side rendering. On the other hand, I like the purity of REST APIs and front end rendering.<p>For technical reasons not worth getting into, on my current project, a SPA would be overkill and hard to implement. But I did take the lessons I learned from my time with Angular to create a poor man&#x27;s model view framework with a combination of HandlebarsJS+JQuery.<p>After my experience doing it, I understand why a framework would be better. I&#x27;m reinventing the wheel (out of necessity), it wouldn&#x27;t scale to multiple developers without becoming an ungodly mess without a framework to keep people on the rails and it would be harder to ramp people up. When I got thrust into my first Angular project it was easy just to read a few articles and watch some PluralSight videos.<p>As the dev lead, I will definitely choose a SPA framework when my next front end project comes up. For all of the reasons above and because it&#x27;s easier to recruit and retain people when you&#x27;re doing the new and shiny that can add to someone&#x27;s resume - including mine.<p>It doesn&#x27;t matter how I feel about the most popular frameworks, if I want to be employable, I need to keep up to date.
seawlfover 7 years ago
I&#x27;ve worked on a number of SPA&#x27;s over the years and I always run into the problem of getting my team to give a shit about performance. &quot;We&#x27;re not Google,&quot; they protest. Frankly for a lot of people it&#x27;s the trade-off of slow client performance for development velocity. It&#x27;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 rendered.
评论 #16304211 未加载
评论 #16304790 未加载
mwcampbellover 7 years ago
For the problem of bundle size, it saddens me that Google&#x27;s Closure Compiler (specifically the advanced mode) hasn&#x27;t gained much traction. This provides fine-grained tree-shaking to minimize the bundle size. But this requires static analysis of the whole program, which is at odds with the dynamism of JavaScript. Maybe now that static typing is coming back into fashion, the Closure Compiler or something like it will gain widespread adoption.
评论 #16305423 未加载
adamnemecekover 7 years ago
One thing that doesn’t get mentioned is that writing an SPA feels more like programming.<p>Writing jquery feels like idk...not quite like programming.
评论 #16303923 未加载
评论 #16303841 未加载
mnm1over 7 years ago
Over 90% of my web browsing is done with JavaScript turned off. When I hit an spa blog I sometimes read it, sometimes not. Clearly if the owner of the blog is so insensitive as to make it an spa, they don&#x27;t care about the content and especially don&#x27;t care about their readers. That&#x27;s fine. There&#x27;s plenty of other content on the web to read. I don&#x27;t understand why it&#x27;s normal to let strangers run code on my computer. Yes, the masses are ignorant of the consequences, but I think that&#x27;s slowly going away as me generations grow up with the internet. Anyway, the upside is that over 90% of web pages I visit load under a second. Imo, people who make their blog, marketing site, etc. an spa blindly don&#x27;t care about their content, presentation, or the reader. Why would the reader care about them?
estover 7 years ago
been a victim of shit corporate SPAs<p>1. tons of widgets&#x2F;slides&#x2F;inputs in one single page<p>2. click submit -&gt; error -&gt; go back -&gt; all filled info gone<p>3. cant open links in new tabs<p>4. cant copy shit off the inputs because text was in some kind of fake div with v-data attribute with disabled cursor movements. Had to use devtools to copy shit<p>5. Naturally, cant paste shit. Had to manually type MD5 checksums.<p>6. Always got redirect to home page after login<p>7. Broken links everywhere. Cant restore page state via link. IDK if this page is broken or still ajax in-progress. Had to open devtools to see if there&#x27;s any js errors<p>8. If page is broken, refresh, boom, all your typed contents and procedures are gone.<p>I think if people cant make a proper &quot;multi&quot; page form based web application, they should not be allowed to engage SPA at all.
sagoover 7 years ago
&gt; [SPA Pro:] frontend is decoupled from backend<p>I was very surprised to read that.<p>Very often validation and context-sensitive behaviour needs to be performed on the client <i>and</i> (since you can&#x27;t trust the client) on the server. You can certainly argue this is better user experience: you don&#x27;t have to wait for a server round-trip before finding out an action is invalid, but it&#x27;s hardly decoupled.<p>Isn&#x27;t this a part of why node is so popular as a server platform? The stack is now so deeply coupled, it is very beneficial to reuse code.
评论 #16304936 未加载
throwaway0255over 7 years ago
One thing I&#x27;m noticing about SPAs is that they&#x27;re often slower to load, but the slowness and loading animations gives me a higher perception of the quality of the application.<p>The same application loading and doing things instantly as server-side templates feels comparatively cheap and un-modern.<p>What is wrong with me?
评论 #16305908 未加载
评论 #16304751 未加载
jconleyover 7 years ago
Many of these pitfalls can be avoided with intelligent server side rendering, which includes the router on the server, so no using client-only “#” URLs. But, that adds another significant layer of complexity to application development.
oaieyover 7 years ago
Just a reminder: <a href="https:&#x2F;&#x2F;varvy.com&#x2F;pagespeed&#x2F;wicked-fast.html" rel="nofollow">https:&#x2F;&#x2F;varvy.com&#x2F;pagespeed&#x2F;wicked-fast.html</a>
osrecover 7 years ago
We built one of our products as an SPA (<a href="https:&#x2F;&#x2F;usebx.com&#x2F;app" rel="nofollow">https:&#x2F;&#x2F;usebx.com&#x2F;app</a>). I have to say it was a fairly enjoyable experience, and our users like it too (they often add it to their home screen and comment that it feels totally native). The only annoying thing was ios Safari, which has it&#x27;s own little quirks in certain areas (but those are not limited to just SPAs but any kind of website).
评论 #16305119 未加载
评论 #16305258 未加载
maligreeover 7 years ago
Is anything ever?<p>Why is there such a strong tendency towards treating things as a this-is-it(-this-time-for-real) thing? This only confuses people and muddles up expectations.
geraldbauerover 7 years ago
Great to see the article posted on a &quot;classic&quot; (static) website built w&#x2F; jekyll. Find more open source (ready-to-fork) themes @ <a href="https:&#x2F;&#x2F;drjekyllthemes.github.io" rel="nofollow">https:&#x2F;&#x2F;drjekyllthemes.github.io</a> Build your own &quot;classic&quot; websites &#x2F; blogs :-).
smnrchrdsover 7 years ago
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?
评论 #16304359 未加载
评论 #16304226 未加载
fictionfutureover 7 years ago
Hold up, most these problems are directly related to the problems of using React+redux (JSX) and likely some complicated backend stuff.<p>We use Vue + Firebase and even have SSR working w no complaints. (So it&#x27;s actually more than just a SPA)
Illniyarover 7 years ago
This might not be a popular opinion here, but yes, SPAs are indeed a silver bullet.<p>Or at least, no you shouldn&#x27;t make a site that isn&#x27;t SPA. With universal rendering, light frameworks like Preact&#x2F;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.<p>It&#x27;s simply that many developers&#x2F;managers don&#x27;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.<p>I don&#x27;t think reloading the entire page on every request is acceptable in 2018, even if it&#x27;s a blog.
jaxnover 7 years ago
What about applications that are used day-in and day-out? Applications that average dozens of &quot;page views&quot; per session. It seems that an initial load is worth a better UI.
jaunkstover 7 years ago
When you need an SPA it’s great. JQuery noodles are a past time and I’m not going back. If you need a blog or something just render it all sever-side and sprinkle some JS.
评论 #16305185 未加载
digi_owlover 7 years ago
Frankly SPAs should be served up via a whole different channel, they are effectively an abuse of web tech to NIHing the likes of VNC.
评论 #16305987 未加载
rhizomeover 7 years ago
Can we start a movement to teach tech bloggers what &quot;begging the question&quot; is?
tatersolidover 7 years ago
A lot of misinformation here.<p>SQL Server has had check constraints since at least the year 1996.
tzakrajsover 7 years ago
&quot;Stop writing only SPAs&quot; is advice in the same way as &quot;stop making only left-hand turns&quot;. This article stops short of convincing me to stop biasing towards SPAs because it appears only to reiterate known challenges about SPAs and calls out bad practices (tons of unused javascript libraries). SPA frameworks are pretty damned good and they really can and ought to be used wherever you feel the need because some SPA frameworks are very quick to get started with and can be customized to significantly reduce bloat.