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.

Escaping the SPA rabbit hole with modern Rails

274 pointsby mparramonalmost 7 years ago

21 comments

petefordealmost 7 years ago
I have nothing against SPAs for complex UI interactions. It&#x27;s sort of like taking anti-biotics; there should be a moment of reflection when you should justify your true need, lest the cure be worse than the disease. Most developers of a certain age have come up when it&#x27;s SPA by default, and can&#x27;t truly defend why they need it.<p>In this thread, there are several claims that it&#x27;s impossible to write well-organized jQuery. That sounds an awful lot like dogma to me. Also, your inability to write well-organized code says more about your coding and team-management skills than it does about any one approach. Any tech is only as good as the team using it.<p>A few years ago, Sam Stephenson (who originally wrote the Prototype library, before jQuery was a thing) gave an excellent talk on Turbolinks at RailsConf. I recommend the whole talk (turn it up to 1.5x speed, of course) but at 4:12 he does an amazing job of showing how the SPA path leads to insanity.<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=SWEts0rlezA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=SWEts0rlezA</a><p>Here&#x27;s a mental exercise for you: the next time you start a new project, instead of deciding which SPA framework to use, start with an assumption that an SPA is wild overkill for the first iteration of your application - especially if few people on your team have working expertise with the SPA in question. Then see if you can argue FOR the tech. It&#x27;s much harder to justify something you don&#x27;t need if you start with an honest conversation about how you probably don&#x27;t need it. (This works for throwing out CDs, too: start with the assumption that they are all garbage, they all go. Then force yourself to make logic-based arguments for each one you keep. Your outcome will be night and day from if you start with everything in a keep pile.)
评论 #17482703 未加载
评论 #17484113 未加载
评论 #17493731 未加载
评论 #17487119 未加载
评论 #17486641 未加载
评论 #17482694 未加载
wjosseyalmost 7 years ago
To the author of the article- Kudos! Well written, well reasoned, with minimal hyperbole or unnecessary “X is dead” style declarations. Hope we see more writing like this bubble up to the top on HN.<p>I’m not swayed by the argument, but that’s personal bias. I’m the technical cofounder &#x2F; solo coder of a venture backed startup, and I built our platform on rails 5. I migrated our front end to Vue over the winter and couldn’t be happier.<p>When we started (my cofounder and I) our company in early 2017, it had been a few years since I coded daily, and I’ve never been a front end programmer. I’m not well skilled in JS, so I punted on using any front end frameworks for the first six months. Our entire MVP was rails 5 server side rendered pages, with a dusting of jQuery when needed. It definitely got me as far as I needed it to, but I felt a lot of pain once I began to try to mix in a lot more interactivity in the app. For me, migrating to Vue made a lot of sense and continues to pay dividends. For others, the author’s arguments are probably far more applicable.<p>One area where I deeply agree with the author is around how in JS I often don’t know exactly where I should write certain parts of my code. For a long time, I had a lot of model logic in my Vue components, but that quickly became a nightmare and I’ve abandoned that. Now I use ES6 classes to wrap a bunch of my logic, but even then I still find stuff bleeding places that seem wrong.<p>One thing I also avoided so far was using any state management (a la Vuex). In some rare examples I use a message bus to send information around, but even then that usually triggers a component to go refetch information from the source of truth (the API endpoint). So far this pattern helps to restrict me from making certain lazy choices which will feel good in the moment but become maddening in the future. My app, as such, is not as maximally performant as it could be, but the trade off for the rare update has so far felt worth it.<p>So, to sum it up, as a veteran coder who spends 12 hours a day writing code, but knew rails really well and not any SPA frameworks, I’m sympathetic to the article but respectfully have a different experience.
评论 #17480906 未加载
评论 #17482577 未加载
评论 #17481291 未加载
评论 #17481489 未加载
评论 #17482511 未加载
评论 #17481363 未加载
lucidonealmost 7 years ago
Are you building a website? The practices espoused by the author will be ideal.<p>Are you building a web app? Will you have a mobile client alongside your web app? Using a javascript framework for your client(s) and decoupling your data from it&#x27;s presentation will be a fruitful investment. All of these frameworks and their associated happened for reasons, and they didn&#x27;t involve traditional MVC being good enough for everything.<p>As an aside, I find this viewpoint prevalent in the Rails community and the Rails job I had (so, caveat, I&#x27;m coloured by my personal experience). It also lead to a culture of staunch refusal to learn or do anything new in that job, and the quality of the product suffered. It consequently led to me leaving the job, and being much happier for it.
评论 #17481103 未加载
评论 #17480868 未加载
zmmmmmalmost 7 years ago
I have to admit, I do not know Turbolinks well, but I feel like the author misses something fundamental about the benefits of modern frameworks. It&#x27;s not just about building a giant SPA - component-based design is a huge value proposition.<p>The problem I see at the moment is that client side &quot;apps&quot; - however they are rendered - hit a wall in complexity that is really hard to overcome without a a sane and sensible way to break them down into pieces. Just like every sane regular programming language has concepts of classes or modules or some kind of system for divide-and-conquering problems into pieces, your front end needs that too once it gets complex. And that&#x27;s what these React&#x2F;VueJS frameworks are doing for me. What I like is that they make the <i>right</i> solution - breaking a piece of logic or code into its own component - the <i>easiest</i> solution. So I tend to <i>do the right thing</i>, not because it&#x27;s &quot;the right thing&quot; but because it happens to be the <i>easiest thing to do</i>.<p>I know this is a bit of a parallel argument with respect to whether you build a SPA or not (especially Vue can live in either world just fine). But I feel like the author is throwing out the component-baby with the SPA bathwater.
评论 #17481953 未加载
评论 #17483781 未加载
评论 #17487137 未加载
schizoidboyalmost 7 years ago
&gt; For your SPA logic, you will want a rich model of objects that represent your domain and its rules. And you still need the same for your server logic. And this recipe is just a duplication waiting to happen.<p>Great article overall but one premise I question is: how often do you really need a non-jQuery JS framework at all in the client?<p>It seems to me that most apps are simple CRUD apps and server-side rendering is sufficient. Sprinkle in jQuery for simple client functions. Use jQueryMobile for the SPA framework which improves performance by making an AJAX request for any navigation and replacing the page body (instead of doing a full page reload).<p>I recommend only moving to a full non-jQuery based framework if the design or functions require it (and question that) or the app evolves to require it. As fast as computers, phones, and the internet are today, doing server-side rendering seems good enough for most apps.
评论 #17480846 未加载
评论 #17481101 未加载
评论 #17480821 未加载
Mc_Big_Galmost 7 years ago
Without any input from me and several other js devs in our org, it was decided that we&#x27;ll do a complete rewrite of our Ember.js app in React. The primary reason stated was hiring and the secondary was build times. The first should have been performance but they&#x27;ve been pretending like performance doesn&#x27;t matter and that it&#x27;s good enough. It&#x27;s not.<p>Since it&#x27;s easier to develop, our backend admin system is built in .NET&#x27;s MVC framework and it&#x27;s lightning fast compared to our frontend. Like ridiculously fast. I&#x27;m not currently a backend dev but I have extensive experience with Rails and I&#x27;ve seen the same with Rails. It&#x27;s fast.<p>Despite the fact that I&#x27;m a front-end dev and it&#x27;s not in my best interest, my un-requested recommendation was to do the rewrite in MVC, thus delivering everything from the server side. Here are my stated reasons:<p>• The site will load and responds incredibly fast<p>• The &quot;build time&quot; problem disappears<p>• The &quot;hiring a lot of specialized javascript developers&quot; problem disappears<p>• Backend devs suddenly become full-stack devs<p>• Deploying is easier<p>• Testing, both automated and manual, is easier<p>• SEO is easier<p>• You can now hire junior developers who are productive and don&#x27;t create a mess in a new js framework<p>• It&#x27;s going to be supported for a long time, unlike the latest javascript-framework-of-the-day<p>• Our website is a website full of mostly content and CRUD forms, not an app.<p>We actually have very little &quot;highly interactive&quot; parts of our site and those that we do have can be a light-weight framework or simply a sprinkling of javascript. It should have never been an app in the first place.<p>If everything had been build in Rails from the beginning, instead of .NET and Ember, we would have been twice as productive with half as many developers and wouldn&#x27;t need QA at all if we wrote tests.<p>This opinion was basically scoffed at with no valid counter-arguments given. They will move forward with a complete rewrite in React, which will solve none of their problems, except MAYBE hiring, and likely create more. They&#x27;ll also probably do it without me. I&#x27;m not against SPAs or React when used for the correct reasons, especially considering I&#x27;ve been focused on front-end for the last 5 years, but I am vehemently opposed to bad decision making.
评论 #17480468 未加载
评论 #17482593 未加载
评论 #17480843 未加载
评论 #17483798 未加载
评论 #17483859 未加载
3pt14159almost 7 years ago
I was initially skeptical, but this article nails the issues 100%. His experience mirrors my own and I don&#x27;t think I even had a single place where I disagreed with him.<p>All I would add is that rails can be made to work wonderfully with SPAs if you&#x27;re willing to do some metamagical programming to auto-follow standards like JSON API.
Illniyaralmost 7 years ago
Replacing the entire body with every request seems a bit overkill. If you want SPA interactivity without moving control to the client side, try intercooler.js<p><a href="http:&#x2F;&#x2F;intercoolerjs.org" rel="nofollow">http:&#x2F;&#x2F;intercoolerjs.org</a>
meesterdudealmost 7 years ago
A very well thought out and articulated article.<p>I love Rails and the power it offers in development productivity and quality. It&#x27;s code is very maintainable and actually enjoyable to develop in; even when it&#x27;s someone elses codebase.<p>Oddly enough, I finally came upon a use case in a project where an SPA frontend (Vue) &#x2F; ruby backend make more sense given the platform nature and operational needs (runs on a pi, no &quot;models&quot;)<p>9&#x2F;10 Rails is the way to go though for developing something.
ransom1538almost 7 years ago
Has anyone used jquery mobile?<p>It was an amazing project that let you write normal css&#x2F;html&#x2F;js without modifications THEN rendered the html+js into a SPA. It was fast, preloaded pages, clean, easy to write and really well documented - and maintained the root dom element. BUT! The project is mainly(opinion) dead. Instead people want to write in a new language (react,vue,etc) then deal with adding a massive layer of complexity.
评论 #17480426 未加载
评论 #17480292 未加载
fred123almost 7 years ago
I wonder how the argument changes if you know you need an API for your mobile application that&#x27;s almost identical in features to the web page.<p>If you go the &quot;Rails&#x2F;Django way&quot; with server side rendered templates and, say, a bit of jQuery for fancy stuff -- you&#x27;ll end up duplicating lots of code for the API (validation, routing, maybe even business logic).<p>Anyone got experience with swapping your models&#x2F;controllers for an API while keeping the rest of Django&#x27;s&#x2F;Rails&#x27; niceties? (authentication&#x2F;sessions, Django&#x27;s forms system, CSRF, etc.)<p>OTOH having Django&#x2F;Rails merely as a template system you probably could also go for very simple, self-contained client-rendered JS pages (e.g. .vue files). Not much difference there I guess?
评论 #17487150 未加载
stevebmarkalmost 7 years ago
Rails is a deeply flawed framework, and we need to stop using Basecamp as the example of a well designed monolith. Basecamp is terrible software, and the crappiness of the user interface appears to be a direct result of not being able to build rich interfaces as its coupled to legacy Rails designs like this article suggests. Basecamp being fast while getting a trickle of traffic and working with very little data is not a selling point against SPAs (I&#x27;m not pro or con SPA).
评论 #17483361 未加载
randopalmost 7 years ago
I feel like seeing more and more post about criticisms for workflow or framework that it is becoming unhealthy with the developer community.<p>There is always short comings on every tool and library, and part of responsibility of a good developer is discerning trade-offs.
PythonicAlphaalmost 7 years ago
The main problems addressed in my opinion:<p>- Code duplication between server and client side<p>- Added complication threw data transmission between server and client (REST&#x2F;json)<p>I think, both problems can be addressed by:<p>- having (a single) code that works both on server and client-side<p>- having transparent transport mechanisms for information between client and server.<p>I am sure, I could implement such a thing for Python&#x2F;Django, using the already existing tools. But I am not sure, if such a thing would be appreciated by the community.<p>What do you think?
arwhateveralmost 7 years ago
Using a framework like the F#-to-JavaScript transpiler Fable, along with an application framework like Elmish, provides a really good solution to some of the pitfalls cited in the article (prescriptive architecture, front + back-end code sharing) and gives you some moderately strong type safety to boot.<p>However, the article author&#x27;s list of SPA pitfalls is really good, and are probably not all surmountable by a framework&#x2F;platform.
everdevalmost 7 years ago
Anyone have good experiences with an SPA architecture?
评论 #17482253 未加载
评论 #17481723 未加载
评论 #17483878 未加载
评论 #17481035 未加载
评论 #17481002 未加载
评论 #17480490 未加载
cmjqolalmost 7 years ago
Like others comments , Kudos to the authors.<p>I&#x27;m an SPA Lover ( Angular , Vue ) , but still most of the points raised here a coherent from a back end perspective.<p>That said , a lot of the arguments are basically summed up as :<p>&quot;I don&#x27;t like Front End Dev. because it&#x27;s not as mature as Back End&quot;.<p>I will not lie on this point , JS is a fast evolving ecosystem that sometimes has issues to stabilize. Hence , there is a lot of marketing and self promotion mixed with frameworks sometimes ( Growth Hacking ) pushing for unnecessary tech that dies a few days after they have leaved the Github Trending page.<p>For beginners , when a framework reach a certain threshold ( Github Stars most of the time) they feel like they should hurry and use the framework to stay relevant while most of the time they don&#x27;t need to and the tech is just fluff.<p>My point here is very simple, you are ROR or Django or ASP.NET dev and you love what you do ? As long as you find jobs keep doing this , don&#x27;t bother with Full Stack Fluff.<p>Now that said , I can only encourage the author to do the Angular or Vue tutorial to discover something different. Rails is great ( it&#x27;s empowering a lot of website Github , Airbnb etc... ) but SPA are different and when used properly it&#x27;s hard to go back , the experience is delightful.<p>Most importantly we are getting closer to the serverless era where backend will be completly different from what it is compared as now, and SPA and SSR will likely be the standard in the future.
评论 #17480833 未加载
评论 #17483371 未加载
swlkralmost 7 years ago
I had this same experience. SPAs, especially for small teams and solo developers, hurt more than they help.
cutleralmost 7 years ago
Turbolinks to the rescue. Slay the Javascript overlords!
Bizarroalmost 7 years ago
There was probably a few valid points, but the article was too long with too many flimsy, &quot;try-hard to convince&quot; arguments.
_pdp_almost 7 years ago
Speaking of code duplication in a traditional web app every page is an example of code duplication. How about that?