6 ms·
Architecture no one needs is server side templating
- edude03 8y agoAnother thing that's slightly alluded to here is also having a backend technology that's different than your frontend technology. While I'm not the biggest fan of JS or TS, I can tell you it's much easier to develop your entire application in JS if you need to do any server side rendering. Otherwise you need to maintain two codebases that do the same thing in slightly different ways.
- henrikschroder 8y agoSummary of the article: "Why do we need screwdrivers? I have a hammer, and everything looks like a nail to me!" There is also the added irony of discussing this article on a site that follow the exact opposite of what the article says is the one true solution for the future of web development.
- lnenad 8y agoI love this analogy, and completely agree.
- coldtea 8y ago>Summary of the article: "Why do we need screwdrivers? I have a hammer, and everything looks like a nail to me!" Yeah, that plus actual reasoned arguments that go into detail to make their point.
- brightball 8y agoHe makes a defense of the SPA that boils down to “because it’s easier to manage client side interactions that way.” The kicking point for server side is that the need for client side interaction is overblown. If you are building a tool that people will keep open for hours, by all means...SPA your heart out. If you are building an open-check-close experience like most of the web, SPAs created more problems than they solve.
- bunderbunder 8y agoI'm thinking here of GitHub. GitHub's UI is not suffering for not being an SPA. On the contrary, it's improved by not being an SPA. When I'm browsing a repository, I cmd-click new tabs out all the time, and I also copy/paste links to individual files as of specific commits to coworkers fairly regularly. All of that kind of stuff is very useful UI that you basically get for free with a decent multi-page app. It gets a lot trickier to get right with an SPA. (I'm not actually sure I've ever seen someone pull it off.)
- vbsteven 8y agoYes, when your app is a highly interactive SPA it makes sense to do everything on the client and ignore server side rendering. But when you are just building simple dynamic admin/crm-style sites with some extra interactiveness sprinkled on top I still reach for my trusted Thymeleaf in Java or ERB in rails. Thymeleaf and ERB are a lot more than "just string interpolation". Thymeleaf even uses valid xml attributes so it's not a completely different language. My pages load and paint fast. Most pages don't need all that interactivity. In most projects I have 1 or 2 pages that are interaction-heavy and for those I usually shell out to Vue, and have my server-side templating inject the source JSON in the <script> tag so an extra request for fetching the data is not necessary.
- setquk 8y agoThis article is self-defeating based on its own content and the experience I have developed over the last 20 years. I beg the author to deal with a typical real world application. Not low scope startup stuff but the thousands of 500+ endpoint typical enterprise stuff that 80% of the market actually comprises. This does scale out to the startup and web stuff as well. This approach introduces a lot more pain from experience: 1. Having to maintain and upgrade SPA type frameworks is hell and you have to do that sometimes (think Angular upgrade hell). Can't afford to start again every 5 years. 2. The performance, and the article actually states it, is shitty at the best of times. All it takes is one client running mandatory IE11 on Citrix and you lose a customer. 3. Most of the complexity is hard complexity that has to be there to process rules. Rules are way more complex than you want to run on a client in some cases. 4. They are incredibly difficult to test. Go try testing a big SPA with selenium for example. 5. Security boundaries are terribly difficult to enforce when half of your application isn't inside your control. Having done desktop development for a number of years, the worst turds I've seen are in that space and the SPA brings them all to the web which is one of the most hacked up evolutionary disasters we have ever created. Really our responsibility as engineers, architects, developers is to give the user the best experience and that means the fastest and most reliable one. SPAs are neither. KISS is a mentality we should be using and I can build a better user experience without SPAs. Greg Navis knows what he's talking about.
- jarym 8y agoI have done enterprise stuff for about 20 years too. On the web side I discovered smartclient.com in 2008 and haven’t looked back. And yes I’ve had the IE11 on Citrix experience also :( It’s an SPA, fantastic documentation, customers love it, and there’s an LGPL version of it. My point is not to get you to use it - it is more that SPAs can work and work well in enterprise settings and for both dev teams and users. PS: testing it with selenium is really easy - there’s a piece in the docs on how to do it :)
- setquk 8y agoI use a GWT based application regularly which Smartclient appears to be. No thanks. As for testing with selenium it's more the point that the entire thing is stateful so the user journeys are much more difficult to program which leads to horrible test coupling as you scale the suite out. I suppose you have to ask: Do you have 22,000+ test cases?
- victorNicollet 8y agoWhat happened to progressive enhancement ? Have a website that can be used with JavaScript disabled, then add client-side behavior that enhances the experience. It obviously isn't the best choice for everything, but surely there are many cases where server-generated HTML with a handful of JS enhancements is still the easiest to implement and maintain.
- coldtea 8y ago>What happened to progressive enhancement ? Like Haley Joel Osment, it never got anywhere after the initial hoopla.
- setquk 8y agoIt's still there, being used and is popular. However no one sells training, fads, marketing, conferences, buyouts, ideologies or frameworks based around it though so there's not a lot of fanfare.
- nbevans 8y agoIt is a poorly written article, with an unexpected conclusion. After all the - what feels like ranting and ignoring SPA problems at every opportunity - he ends with a conclusion that the only reason he is using SPA is because they tend to provide a component framework to organise client side code.
- 0XAFFE 8y agoMy biggest gain since last year has been react to render HTML on the server side. Using react with TypeScript you gain a very sane templating language, very good editing support with every ide which supports ts.
- yodon 8y agoAgreed. Next.JS for example is a great and widely adopted tech for doing server-side rendered react. Add in typescript and you have a pretty serious best of both worlds combo.
- arnvald 8y agoI've been working with SPAs for the last 4 years and I must say I can't decide which approach is better. I believe SPAs provide better user experience, but the cost of that is significant. Also, not every component-based page must be an SPA. You can have multiple pages, each of them having some components. Regarding the article, it feels like author is angry that someone prefers server-side approach instead of his favourite way of developing apps. I disagree with a bunch of arguments in the article: > (about server-side templates) For any large application (by large I mean more than 50 individually developed screens) this slowly becomes harder to maintain. 50 server-side templates vs 50 stateful components, I really don't see why the former is harder to maintain > (about server-side templates) How to name things — when everything is dynamic, naming becomes hard. Again, no idea why naming would be easier with SPAs > Use runtime templating after AJAX call is done. We cannot use server side rendering any more — or can we? Let’s write endpoints that return HTML and not JSON. Or course we can do that, why not? Even more - when lazily loading templates in component framework like Angular, I need to not only download the template that's in HTML, but also Angular needs to compile that template. > Let’s be honest — the only way one can say developing SPA application is costly is if they either don’t know any SPA technology or if they don’t want to learn it. I don't have any hard data, but neither does the author, so I guess we'll focus on personal experience. From my experience keeping state only in the backend is easier to maintain and therefore cheaper than keeping the state both in the backend and in the frontend. > Knowing server side templating language. Also not being able to use the same language for AJAX templating. But to write client components I also need to learn some Angular templating syntax or JSX or some other stuff. And it's not simpler to learn than let's say PHP templating. If I use PHP for my backend, then I don't need to learn template language, because I just use HTML + embedded PHP. > If you have proper mobile app, an API has to be developed for that. Having two layers accessing the same data in two different ways is not practical. That's a fair point, however it doesn't make a big difference. Using SPA I need to develop JSON API + mobile views + SPA components Using multi page app, I need to develop JSON API + mobile views + server side templates > State on the client — because that is where the state belongs to. But why? The state does not need to belong to the client. The client might be a representation of the state that comes from the server.
- dustinmoris 8y agoI admit I didn't finish reading this blog article because the author completely lost me when saying weird things like: - Templating language is basically string interpolation which builds the presentational layer at load time. First of all, what is load time? There is compile time and runtime and then there is runtime on the server and runtime on the client. Load time is just fuzzy language and has no meaning IMHO. Also, what the blimming heck does he mean by string interpolation? Most server side templating engines are compiled, rarely string concatenated and even if that was true, how is that different on the client side? If JavaScript code dynamically creates HTML markup then it also (at some level) stitches string together or does it not? > Client side code is developed separately and has to “pick up” the target elements after it is loaded. Huge news announcements! The client side code has to "PICK UP" the response which the server sends to the client! OMG!!! Thank god in a SPA the client code doesn't have to "pick up" server side generated objects, right? (NOT) > Templating languages are basically smart string interpolators and have quirky syntax. Quirky syntax? First of all, pick an engine which isn't quirky if that's your problem, and secondly EVERY templating engine, regardless of server/client side has a "quirky syntax" if you wish. It's not like front end development is done without a framework or library which gives you more power than just rudimental HTML markup. > One language (server side) is generating markup for a different language which takes over on the client. One language generates output of another language is his problem? So I guess he doesn't use anything but pure JavaScript, because anything on top of pure JavaScript is another language generating JavaScript, right? Also the "server somehow takes over on the client"? What does that even mean, seriously? > If AJAX is used to dynamically alter the state of our app by means of adding, ... How did he transition from C# + Razor to AJAX. Did I miss something? Razor is not AJAX... > Taking paradigms that work well for static documents and using them for building software is simply inadequate. OMFG. client-server communication is not a paradigm for static documents. PDF is static documents. Honestly... I stop at this point.. I can't read anymore. It's painful.
- tpetrina 8y agoAuthor here. > First of all, what is load time? Load time is when server is generating HTML for request. I should have been more precise. > Most server side templating engines are compiled, rarely string concatenated and even if that was true, how is that different on the client side? If JavaScript code dynamically creates HTML markup then it also (at some level) stitches string together or does it not Templating languages generate string that is returned through an endpoint. Just because it is string interpolation doesn't mean it cannot have loops. Also, by using the phrase "string interpolation" I am actually pointing out the discrepancy between the generator and the generated. > Huge news announcements! The client side code has to "PICK UP" the response which the server sends to the client! OMG!!! Thank god in a SPA the client code doesn't have to "pick up" server side generated objects, right? (NOT) It is not response, you have to give unique id's or smart class names and then find those elements using document.getElementById and attach to it. Having a SPA helps reduce the number of named things. > OMFG. client-server communication is not a paradigm for static documents. PDF is static documents. It's not a paradigm, but client asking server for a response is more suited for documents when you are returning HTML.
- fenk85 8y agoI went from maintaining a large site (million active visitors a month for over a decade) where stuff is rendered server side (php+twig in back, jquery+bootstrap in front) to working on in "enterprise" where we have a sprinboo backend + react frontend. The first still loads faster and is easier to maintain by me alone in my spare time, the one at work has 1/10th the usage and functionality and requires a team of 5 people and is still slow and buggy. React promises a lot but the page is 10x larger in size (after being minified + compressed via webpack) and the js code written by my predecessors resembles spaghetti, with redux being used a overglorified goto something to be said for how things were done 10 years ago, and how kids nowadays are reinventing the wheel every month in JS (and still are behind where we are with kotlin in backend for example)
- joelbluminator 8y agoAll the front end devs are trying to protect their jobs hehe...
- tluyben2 8y agoWhy did this article get so high up? I was going to respond to it, but everyone here already told why this all is poorly written with no/poor foundations. So wondering who upvotes this kind of stuff.
- wwweston 8y agoI think SPAs can be a decent choice for certain classes of applications, but this article seems really weird to me. > Templating languages are basically smart string interpolators and have quirky syntax. Well, yes, templating languages take a string + data and return another string. That's definitely true. What that actually means isn't clear. Especially when the followup "have a quirky syntax" doesn't have a particularly precise meaning (and may not be universally true) and also, the problem remains the same whether you address it on the server or in the client. > We cannot use server side rendering any more — or can we? Let’s write endpoints that return HTML and not JSON. I can't tell if that last part is sarcasm, or attempt to examine a potential avenue, or a complaint that one would have to multiply endpoints in order to return JSON or HTML instead of having a back-end that pays attention to the HTTP Accept header and has capabilities of returning different representations of the same resource. > When to subscribe/unsubscribe from events. Otherwise we will run into memory leaks. This is also hard to decipher -- is he talking about event listeners on replaced portions of a document? > How to name things — when everything is dynamic, naming becomes hard. As the saying goes, naming is one of the two hard problems in software. The browser is itself a dynamic environment with a dynamic primary runtime. There are languages that'll help or hobble you in the browser or on the server but that's orthogonal to whether you're choosing an SPA. There might be a kernel of a worthwhile argument in here about component testing and isolation being more difficult if you're doing it on both the server and the client, but the rest of this seems thinly justified rather than reasonably explored.
- mercer 8y ago> When to subscribe/unsubscribe from events. Otherwise we will run into memory leaks. This strikes me as a non-issue if you still use React or the like for the dynamic elements of your page. Furthermore, if anything, having full refreshes makes the problem of memory leaks less of an issue!
- wlll 8y agoFlipping this round, as a user heavy use of Javascript significantly reduces my enjoyment/increases my frustration of the web. I get that some tools work better when written as SPAs, but most stuff, like my bank, news sites, most stuff really, is better without it IMO/IME.
- ttty 8y agoYou mean bad use of JavaScript. Modern websites can prefetch all possible links on the current page you're seeing. Then when you click on any link will render that page instantly. Check out some Gatsby blog generator, it's so fast.
- alehander42 8y ago[not op] But what if I don't want them to prefetch it?
- wlll 8y agoNot really, no. > Modern websites can prefetch all possible links on the current page you're seeing. I'm not sure I actually want that to happen. > Then when you click on any link will render that page instantly. Check out some Gatsby blog generator, it's so fast. Most of the time I visit a single page on any given blog, usually found via Google. If I have to load any JS at all the chances are I've downloaded more code than I needed. If the content requires downloading a framework before viewing the content then it just adds to the frustration. It's totally possible to serve HTML, some styles, and some feature-enhancing javscript /fast enough/, and my experience of the evolution of Javascript on web pages over the last 18 years has led to the opinion that Javascript has steadily made my experience of the web slower, more CPU intensive (my CPU fans being spun up by someone's attempt at improving the UI of a web page isn't appreciated), less reliable, less predictable and in general, worse. There is the very real possibility that if you write and release a Javascript based web page then I will enjoy it less than if it was something "simpler".
- ssijak 8y agoI find SPAs much easier to work with, maintain, reason about, especially as the application grows. I have experience with both server side rendering with Java and with SPAs and for the majority of usecases I would prefer an SPA but maybe that is just me. There are a lot of resons for my preference, but as with everything, we must not be blinded with our choices and use the right tool for each job.
- quickthrower2 8y agoThe thing is that for most business web apps rendering on the server side and sprinkling in some JQuery validation is good enough, and a pretty solid approach. Frameworks like Ruby on Rails or ASP.NET MVC provide a lot of infrastructure to do this, and it is easy to find people skilled in maintaining this. My last job was like this, my current job is more of a SPA but mostly because it needs to be, because of what it is. I always thing "horses for courses" when people make opinionated statements about what tech you should use.
- mschaef 8y agoI tend to think of it in terms of horses for courses. In other words, let your requirements drive your architectural choices, rather than going in with the preconceived notion that there are architectures 'no one needs'. I recently threw together a small blog engine and wouldn't even have thought of writing it as an SPA... there was no point. Then again, a blog is mostly static document service, so it shouldn't be a surprise that picking a document service architecture made sense. For me at least, some of the specific reasons to pick an SPA might be this: * I'd like my user to be able to make change to a document without disrupting where they've scrolled in the document. * It's possible to build retry logic into the SPA to get a bit of offline capability if the network connection isn't great. * There's a block of data on a page that takes an unmanageably long time to render and I'm okay with it showing up after the body of the page. * There's a large volume of data that can be maintained and incrementally updated within the client, rather than reload every time. * There's a need to automatically stream and update the page in real time (and meta refresh, etc. won't work.) * The developers assigned to the project are more comfortable with SPA and associated tooling. * There is a high likelihood of one of the above becoming true soon enough that we wouldn't be able to rewrite to an SPA to accommodate the requirement when it arises. Not exhaustive, but a big list anyway.... so there are often good reasons to select an SPA design. But not always. As engineers/architects, we have to do the work of understanding the requirements and planning our design..
- bunderbunder 8y agoMany of those serve as great examples of times when you might want to add AJAX-y elements to your design. I don't want to imply you were suggesting this, but it bears mentioning that a lot of the SPA vs MPA debate rests on a false dichotomy, where "MPA" is taken to imply that you're partying like it's 1999.
- mschaef 8y ago> I don't want to imply you were suggesting this Actually, I kinda was. Maybe a better way to put it is that I'm looking for more fluency of control in where the application code actually runs. I'm less interested in having 'an SPA' or 'an MPA' and more interested in tooling that makes it possible to more easily select between SPA and MPA characteristics for various parts of a given UI. Edit: to make this a bit more real, here's a few thoughts on what that might look like: * Same language on both client and server. * Same templating on both client and server. * Some sort of lightweight RPC-style mechanism for exposing server functionality up to the client. (Without a fully specified protocol/format/etc.) * Framework provides an endpoint that serves up a JavaScript projection/transpile of some subset of the overall application code. * Same thing for CSS. * The usual automatic reload/refresh-on-change logic you get with modern client stacks. * Setup is essentially 'add a plugin or maybe two to the project build script'.
- candiodari 8y agoThe basic problem with SPA is simple: 1) Request handling until you have a functional app in, say PHP: GET Reply (page displays at this point) So: 1 RT happens. 2) In an SPA GET the html reply Get the javascript reply Get javascript dependencies (usually multiple) replies Get the data to display (again usually multiple requests, because nobody does the call combining you should do (ie. don't have GetUserData(), GetFrontpageItems(), GetMessages(). Instead have GetAllStartupStuff() that returns all 3, to avoid the extra roundtrips) reply So: 4 RT Minimum Guess which is the overriding cost in any webapp ? Yep, the roundtrip. Guess why we do this SPA thing ? Why, we do it because it's faster, of course ! (this is so ridiculous it's sad)
- forgottenpass 8y agoI love waiting for a website to load twice. Once for the placeholder graphics, then again the real data.