44 ms·
A tale of webpage speed, or throwing away React
- ForHackernews 6y agoIs this approach similar to Rails Turbolinks?[0] [0] https://github.com/turbolinks/turbolinks https://github.com/turbolinks/turbolinks
- jack_riminton 6y agoI think it’s more similar to Stimulus or StimulusReflex? ie you can declare the targets and actions of the JS within the html tags
- thrownaway954 6y agonot really. turbolinks replaces the entire body when you click a link, there is now way to replace just a portion of the page. pjax would be a better OG similarity: https://github.com/defunkt/jquery-pjax https://github.com/defunkt/jquery-pjax
- mariopt 6y agoThat 5/100 score is very very strange. Have you tried migrating your react code base to NextJs?
- ColeyG 6y agoRight? I think there was something architecturally wrong with the app that the refactor fixed. It doesn't sound like react was the problem here. I sincerely don't believe that this sort of change and therefore the decrying of react for it makes much sense at all without seeing this guy's code.
- terenceng2010 6y agoIn the article though he does not mention whether React with SSR is an option?
- piranha 6y agoIt always had server side rendering. https://solovyov.net/blog/2017/server-side-rendering/ https://solovyov.net/blog/2017/server-side-rendering/
- lf-non 6y agoNot opposed to server rendering or backend heavy sites, but a lot of people are able to get much better Lighthouse scores for fairly complex sites through a combination of webpack code splitting, service-worker based caching, and CDNs. So, the problems here may have had more to do with the clojurescript stack (which I am not much familiar with), or author's lack of familiarity with javascript optimization strategies than react, SPA model or client side rendering.
- rjknight 6y agoCode-splitting is supported in ClojureScript. Compiled CLJS is just JS, so service workers and CDNs should work in the same way. However, CLJS really does feel like application development (which is why I like it, tbh) and the community doesn't seem to pay much attention to the use-case of regular web pages which just need some JS components to add interactivity. Googling for strategies to optimise CLJS for that use-case won't get you many results - you have to understand the stack well enough to do it yourself.
- RedShift1 6y agoLooks like we've come full circle? First server side rendering, then client side, now server side again?
- sovietmudkipz 6y ago<jokes>Time to go bear on “client side” shares and bull on “server side” shares. Quick, grab as much PHP as you can get!</jokes> All joking aside, I would argue the client side vs server side is a false dichotomy. The web has been doing a hybrid of both for a very long time now. Each have their pros and cons and there hasn’t been anything stopping engineers from using a mix of both, where it makes sense. Now about those cargo cult marketers...
- darepublic 6y agoServer side again was already in vogue back in 2016ish. What we need to do now is go back to client side
- krzepah 6y agoYou can do server-side rendering with react. I'm pretty sure ppl started doing so at least 5 years ago
- capableweb 6y ago> we’ve discovered that React also leads to some questionable practices. Like hovers in JS (rather than in CSS), drop-down menus in JS, not rendering hidden (under a hover) text (Google won’t be happy), weird complex logic (since it’s possible!), etc. This is some strange reasoning that I have yet to seen myself. If you can do the hovers states/drop down menus in CSS, why not do them in CSS, even if you're using React? Seems to be blaming something on a library that the library has no care about in the first place (which to be frank, seems relatively common in web dev circles). > In the worst case, we would serve you 2.5MB of minified (non-gzipped) JS And holy guacamoly, how do you end up with this?! Seems that something was surely wrong in the compilation options, forgetting to mangle names or something, missing dead-tree elimination maybe?
- swyx 6y agothey were using handrolled SSR in clojurescript, I'm not sure they set up code splitting.
- capableweb 6y ago> I'm not sure they set up code splitting Don't think that matters. I've written (from scratch and inherited) and deployed many ClojureScript frontends, from one page ones with lots of interactivity to 30+ pages/sections, none of them reaching the size of 2.5MB minified (when using the production settings for Closure Compiler). Add in SSR and/or code splitting and the weight should be nowhere near there, leading to the guess that something is wrong in their config or they are embedding binary files into the JS asset.
- piranha 6y agoOh yeah, binary assets. Yeah, it is certainly binary assets. We just embed node.js in there. /s
- deleted 6y ago[deleted]
- 6y ago
- tom_walters 6y agoThis is the typical "we didn't spend any time thinking about our architecture therefore we're going to blame our framework" article. React is a great choice for certain use-cases, but when low-quality developers are allowed to pick it up and apply it to everything you end up in a mess. The same thing happens with literally any tool. If you want speedy initial interaction times and manageable codebases, (and requirement X) use the right tools for the job, and instil better, thoughtful, development culture.
- piranha 6y agoThis is typical "I drink React kool-aid so I'll never give benefit of the doubt to anybody who's not supporting my point of view" comment.
- Udik 6y agoIn general, these posts sound a bit like this: I tried jQuery, and after a while it all became a mess; took up a Backbone project, and was good for a while, but eventually it became too complex; then I worked on Angular and that seemed a big improvement, but then... and finally with React my architectures are clean. While the reality is more like this: I had 6 months of programming experience and used jQuery and made a disaster; with 1.5 years of experience I used Backbone and I fared better; with 3 years of experience I tried Angular and I was able to build a decent size application but ultimately shot myself in the foot; and now that I have 6 years of experience my software quality has improved a lot, it must be react!
- mgkimsal 6y agoI would change it a bit and suggest that after angular, they did react, and after 18 months of that it was too convoluted, but 'hooks' solved everything, and then 12-18 months after that, things are just way too complex, and they're now investigating svelte or something else. I rarely see any decent architecture survive growth and real world use beyond a couple years. It's usually either 1) "no one could possibly have foreseen this new use case/requirement" (from less experienced folks) or 2) "YAGNI!" when trying to build in some abstraction levels to handle use cases you know will happen down the road.
- swyx 6y ago> we’ve discovered that React also leads to some questionable practices. Like hovers in JS (rather than in CSS), drop-down menus in JS, not rendering hidden (under a hover) text (Google won’t be happy), weird complex logic (since it’s possible!), etc. You can have a React app without those problems, but apparently, you have to have better self-control than we had (nobody’s perfect!). idk if this is fair. OP was using some pretty niche tools (clojure) whereas best practice React metaframeworks like Nextjs may have addressed some of those pagespeed issues. additionally, I highly doubt that the author has replicated this functionality by using his new turbolinky framework. So the post is better titled "I improved webpage speed by throwing away React AND a bunch of UI requirements". which is fair dinkum, but less exciting.
- piranha 6y ago> additionally, I highly doubt that the author has replicated this functionality by using his new turbolinky framework. Which functionality? > a bunch of UI requirements So your point is that you don't really know, but let's blame them for trying, or what?
- vezycash 6y agoIt's hard but take a few minutes off before responding to snarky comments. Please answer their indirect question: "Did you replicate every of the react app's functionality in the app?"
- piranha 6y agoThis is why it took four months, we had to change all React-isms to something that works in both modes. One particular thing could load less HTML, and it'll require some attention to make it so - but as we're deprecating React version of catalogue, it'll be easier to do.
- yowlingcat 6y ago> So your point is that you don't really know, but let's blame them for trying, or what? I think GP's post is that _you_ don't really know the landscape which was why you reinvented the wheel, which I tend to agree with. You even agree with this unless you're being rhetorical here, no? > Which functionality? Let's take a look at every feature we see on the next.js page (https://nextjs.org/ https://nextjs.org/): Zero Config Automatic compilation and bundling. Optimized for production from the start. Hybrid: SSG and SSR Pre-render pages at build time (SSG) or request time (SSR) in a single project. Incremental Static Generation Add and update statically pre-rendered pages incrementally after build time. TypeScript Support Automatic TypeScript configuration and compilation. Fast Refresh Fast, reliable live-editing experience, as proven at Facebook scale. File-system Routing Every component in the pages directory becomes a route. API Routes Optionally create API endpoints to provide backend functionality. Built-in CSS Support Create component-level styles with CSS modules. Built-in Sass support. Code-splitting and Bundling Optimized bundle splitting algorithm created by the Google Chrome team. Now, do you want some or any of these things? How long do you think it will take to incorporate them into your new tool which you just rolled from scratch? I guess at this point I'll add in some opinionated views here. At a certain point along your software engineer journey towards becoming a senior engineer, you are supposed to understand that undifferentiated heavy lifting and implementation is a bad strategic move in terms of technical strategy. If I am your CTO and you are telling me that you want to write your own Intercooler-esque library and move all of our core frontend checkout code away from React (an ecosystem with conventions that much of the rest of the world uses) and towards a proprietary solution I am going to ask you for a good reason. That is to say, I am unlikely to be persuaded by "I didn't spend enough time deeply researching how the rest of the ecosystem's users handle these issues" and I am likely to gently remind you that we will likely get more mileage out of investments that make our user experience better rather than scratching the itch to write a new framework.
- madeofpalk 6y agoHow on earth does React encourage the bad practice of “hovers in JS”? React absolutely has zero influence on this - that one is entirely on the developers. I’m also exceptionally confused why the Pagespeed score was sitting at just 5/100 - it doesn’t sound like the dev team actually understood the result and attempted to resolve it. It sounds like the author has found some new technology they’re happy with for now, but it sounds like all the previous problem were self inflicted and they’re bound to repeat them again. While different tech and frameworks has an influence in the problems you’ll face, you’ve still got to do good programming.
- schwartzworld 6y agoIf you are writing JS styles, you don't have access to pseudoselectors like :hover. A quick solution adopted by many is simulating hover with onMouseEnter and onMouseLeave event handlers. This can be remedied by using CSS or styled-components.
- madeofpalk 6y agoThis is nowhere near a common practice (I've never seen it on any work project, or on community projects). React does not promote or advocate or make it easier to do it this way, rather than the proper way in CSS.
- schwartzworld 6y agoIt is actually in the react documentation. https://reactjs.org/docs/dom-elements.html#style https://reactjs.org/docs/dom-elements.html#style I'm not saying that's how it should be done. I'm just clarifying what the author of the article was referring to.
- madeofpalk 6y agoCorrect, it is documented. That's what documentation is - to list out and describe the API surface. The entire documentation block for that is prefixed with a big yellow-box warning: > using the style attribute as the primary means of styling elements is generally not recommended. And then it links to https://reactjs.org/docs/faq-styling.html https://reactjs.org/docs/faq-styling.html which just says over and over again "use class names"
- llimos 6y agoFor sites that are content-heavy I've started wondering if it makes sense to have the content server-side rendered the old-fashioned way, and use multiple React roots for the parts of the page that need to be interactive. You can still use Redux etc. for managing app state globally (though not React context), and you get most of the gains of load time, and of using React where you need it. It seems everyone uses <body><div id="app-root"></div></body> but React is perfectly happy being scattered around the page. It's just a thought, I haven't tried it myself yet - has anyone else?
- ncrmro 6y agoThis map is actually a wordpress plugin that loads locations from google sheets into a JS var that a react bundles loads. Client already had the rest of the site built in Wordpress so easier to just make a plug-in with a shortcode that loads the react bundle into a div. I and some other built while i was at Poetic in Houston, Tx. https://www.houstonfoodbank.org/find-help/agency-locator/ https://www.houstonfoodbank.org/find-help/agency-locator/
- sovietmudkipz 6y agoAt my old company we did this approach for some of our pages. We were transitioning away from our old codebase page by page but rewriting the codebase took longer. New features were still desired so we built/repurposed react/redux components into what we called “hybrid” pages. It worked great for us!
- renke1 6y agoReact Portals could also help here, allowing you to still use context and the like.
- CaptArmchair 6y agoDepends on your business case / use case and where you want to draw lines. A lot rides on which parts you perceive as being "application" and which parts aren't. For instance, you could build an e-commerce shop as an SPA, or you could target specific parts that process user interaction dynamically / fluidly - such as the checkout process, adding to a cart,... - and consider those as separate applications. There are also trade offs. Search and navigation, for instance. You could build an SPA for an entire search engine. But then you may end up doing heavy lifting, like dynamically managing URL state through routing components, which is something browsers already do themselves: the only gain being that you don't reload the entire page. So, the big question boils down to: what are you really trying to solve? A UI/UX problem? A performance problem? A maintenance problem? Something else? And who are the stakeholders, who's using the stuff you're gonna build? What are their intentions and motives? That's when you come, to a conclusion: there's no silver bullet. The architectural design you choose needs to be an informed choice above anything else. And it should be informed by your specific context rather then the affordances provided by the tools at your disposal. The hard part is sitting down and taking a bit of time up front to think and articulate an argument that, given your context, validates choosing a particular strategy. (Personally, I tend to sit back and stare at the ceiling with my notebook and a pencil, but that's just me.)
- davidtranjs 6y agoAll of your issues like dropdown and hover in JS can be solved by CSS, why did you choose to implement them in JS? About complex logic, it is everywhere. I once worked at an big ecommerce company and the server-side catalog page was more then 2000 lines, nobody want to touch that page. But it would be easier with React since we can break it down to smaller components. Your 2.5MB minified bundle is actually too big.
- tjpnz 6y ago>All of your issues like dropdown and hover in JS can be solved by CSS, why did you choose to implement them in JS? Because it's modern? In all seriousness I've often asked questions along these lines and haven't always received great answers.
- deleted 6y ago[deleted]
- onion2k 6y agoWe need to look at it from two sides: if it’s good for developers and if it’s good for users. React was great at former and terrible at later. React is not "bad for users". Developers build complex, fast apps with React all the time. It can be fast, but if you make mistakes with it then it's easy to make something very, very slow. The app I work on is huge. It's ~8MB of uncompressed React + Redux in development (much smaller in production though), and pages include a lot of assets so they can weigh in at 23MB in the worst cases. A complex page can have up to 60,000 DOM nodes under React's control with thousands of event listeners. It starts in about 3s and never drops below 60fps.
- voldacar 6y agoHow performant! How performant!
- deleted 6y ago[deleted]
- lgl 6y ago> A complex page can have up to 60,000 DOM nodes under React's control with thousands of event listeners. It starts in about 3s and never drops below 60fps Can one really make such affirmations regarding client rendered web apps? I'm assuming these numbers aren't solely measured on localhost in some state of the art development machine/device so won't it depend on the client's machine specs, browser, usage, bandwidth, etc?
- schwartzworld 6y agoI don't know what bandwidth has to do with react managing the DOM.
- onion2k 6y agoA naively built app will do things like take some user input from a form, send it off to an API and await the response, and then update the UI when if the request is successful or display an error if there's a problem. That means the user has to wait for the request to complete before moving on to their next task. In other words, the DOM update waits for the network. If you have a slow connection that feels horrible (snarky frontend dev note - if you build a server-side rendered app it's how everything in the app works. Sucks if you have a slow connection.) It's better for the user if the UI assumes the request has been successful and updates the UI with a temporary success state, and then undoes the update if the request fails and gives the user the option to recover their update and try again. Most of the time there won't be a problem (especially with good client side validation) so they'll never see the recover state, and they'll never need to wait for a network request to finish either. Obviously you shouldn't use that sort of UX pattern for critical things though.
- blickentwapft 6y agoYou can populate an ordinary web page with some react and get the best of both worlds. Plain javascript is painful. It’s nit necessary to throw out react to address the issues identified here. The author comes across as fairly junior.
- andybak 6y ago> Plain javascript is painful. Which is exactly why he isn't advocating plain javascript. You should take a look at micro-frameworks like Intercooler (and htmx, unpoly alpinejs etc). For devs who don't remember the days before megaframeworks it can be quite illuminating to see a different way of looking at things.
- ojosilva 6y agoIn short, the OP changed the architecture from a client-side rendered app (in React) to a server-side rendered one (built on a custom-made framework cloned from Intercooler.js) and that resulted in a significant performance improvement for their app. Overall not a good critique of React as such to justify the "throwing away React" title in the front page of HN. In fact, not a lot of good conclusions can be drawn from the read. Maybe just "if YOU build/find YOUR own framework for YOUR problem space excitement will follow." On the other hand, I doubt the complexity issues, also mentioned by the OP throughout the article, was solved by using the new framework. In fact: > On the developer side, I think React is better still So tit-for-tat.
- piranha 6y agoOkay, maybe I should elaborate a bit on that. But React is better for developer experience like it is. But when you're talking about code splitting and service workers and other crap it's just a deepest rabbit hole out there. It's unmanageable.
- adventured 6y ago6-12 months from now another article will be warranted, the author will have changed their mind again. That's the pattern you see throughout the entire thing, non-stop jumping. It's a solid bet as an indicator of the lack of maturity as a developer, incessant tech hopping.
- murkt 6y agoYou mean in nine years its Backbone, then React, then server-side rendering? Yeah, that’s tech hopping every 6 months in its finest.
- deleted 6y ago[deleted]
- andybak 6y ago> So I made a proof-of-concept implementation of our catalogue page in Intercooler and it worked! Except there was a dependency on jQuery and some other irritating stuff… Actually the original author of Intercooler has a renamed 2.0 version that removes some warts - including the jQuery dependency: https://htmx.org/ https://htmx.org/
- majewsky 6y agoHTMX is discussed further down in the same article.
- hliyan 6y agoWhen I first read the haiku at the bottom of the HTMX homepage, I had a flash of insight. javascript fatigue: longing for a hypertext already in hand What are we doing? State management libraries? Hypermedia is the engine of application state. Send data to client as HTML and have the client apply styles over it, rather than converting from JSON to local objects and storing in some sort of reactive data store. You will find that semantically structured HTML is almost as economical as JSON.
- kungato 6y agoWhy does is handling state on the backend better than handling it on the frontend? You will always have the cost of waiting for the server to return the full html every time you want something to happend and still you will have cases where you are handling state on the frontend
- hliyan 6y agoTheoretically, you have a point. Practically, you are reading this comment on a website that not only does exactly this, but refreshes the entire page (rather than a small block of HTML, intercooler-style). The performance benefits are evident.
- wwright 6y agoThis site also has almost no state at all per-user.
- jevgeni 6y agoSurprised Solid hasn’t been mentioned. This: https://github.com/ryansolid/solid https://github.com/ryansolid/solid
- theobeers 6y agoAh, thanks! I was leafing through the Svelte tutorial recently, and I knew I’d read about this other project, but I couldn’t remember the name.
- jevgeni 6y agoI like it more than Svelte, personally. A little bit less magic (i.e. easier to reason about) and more performance.
- griffiths 6y agoAnd the author of the library has great knowledge in this domain. The latest release has the new SSR features added (https://github.com/ryansolid/solid/issues/109#issuecomment-674173978 https://github.com/ryansolid/solid/issues/109#issuecomment-6...). I would also recommend to anyone to read his blogs about different approaches to client side rendering, and the technology behind Solid. It is a really good read regardless of the choice of using the library.
- icemelt8 6y agoMy real last straw with React was when I made a dead simple blog with NextJS, hosted it on Vercel as a static site, and still I can't get a good score. My blog: https://www.automark.pk/ https://www.automark.pk/
- Brajeshwar 6y agoHere is an old story from 2016 but I hope this 3-part article is useful. We used React during its early days, to help Aditya Birla with one of their eCommerce websites. 1. https://alarisprime.blog/e-commerce-case-study-building-faster-listing-pages-on-abof-com-part-1-cb99231a1e8a https://alarisprime.blog/e-commerce-case-study-building-fast... 2. https://alarisprime.blog/e-commerce-case-study-building-faster-listing-pages-on-abof-com-part-2-9aa0ac734c08 https://alarisprime.blog/e-commerce-case-study-building-fast... 3. https://alarisprime.blog/e-commerce-case-study-building-faster-listing-pages-on-abof-com-part-3-4e4d32e0e884 https://alarisprime.blog/e-commerce-case-study-building-fast...
- mercer 6y agoAs others have commented, this doesn't seem like it's React's fault. But it does illustrate how React isn't a magical solution to the front-end woes and how complicated the whole thing still is to do right. I'd still use React for projects, but for now I've been incredibly happy with the LiveView solution that Phoenix/Elixir offers (or the variants for other frameworks. Blazor for C#, LightWire for Laravel/PHP?). It's surprising how often I'll work on something and realize that the solution is quite simple now, where before it would definitely mean some serious thinking. For example: libraries. I remember so many projects where I needed do do some date formatting or manipulation. Moment.js was the obvious solution, but including the whole library was not an option. With LiveView I can just pull in whatever dependency I want, because it's all server-side. It's only the markup diff for the specific component that gets sent down the wire. Or security. I need to show a user, but only a 'friend' can see the email address (or other profile details). The 'old-fashioned' way would involve separate API calls and a certain nervousness that perhaps I might end up in a situation where the front-end behaves how I expect, but the API calls somehow expose non-friend data. With LiveView I can just add a conditional statement to the view, and since the resulting HTML is all that does to the client, I'm done! Of course this only works with a persistent and relatively low-latency connection, but I can't remember the last time I worked on a project where this wasn't an implicit assumption. I'm perfectly happy using React/Next/Vue when necessary, but it's a really strange experience to read these kinds of articles and threads these days when for so much of my day to day these problems just went away.
- piranha 6y agoLiveView is also very interesting. The main reason we went other way is that amount of connections and state held on server will be really high, plus we have some clients with bad connections and regular HTTP works much better on those than websockets.
- emerongi 6y agoLiveView can use HTTP longpolling.
- rawoke083600 6y agoJust use Svelte. It's a super simple API, the "trickiest" part is the "reactive sections" but the whole API and reactivity part you can grok in an afternoon. In the past I have used Angular and React - these days I just always reach for Svelte (speed and simplicity).
- skc 6y agoI was happy learning Svelte, felt like a breath of fresh air with how simple it was in comparison to the other more popular frameworks...but then when I started to kick the tires of Sapper I quickly realized that that's where all the complexity was shunted to
- leeman2016 6y agoI really had a pleasant experience with svelte recently. Highly recommend Smaller bundles, faster, easier to use ... everything one can ask for
- kissgyorgy 6y agoThis seems to me yet another story of "We didn't knew X enough, so we switched to Y" or even worse, "we implemented our own". No framework solves the problems of knowing your tools and learning every day, React is no different, not a red pill for every problem, you have to know it's quirks the same way just any other language/framework/tool you use.
- _benj 6y agoReading all of the cynicism on the comments I wonder if we are taking into account the business context for the development of the app. I’m not a fan of react even though I use it daily, but the licentious nature of react allows me to build/modify features pretty quickly, albeit, low quality. I’m as idealist as the next person about a good architecture, but if the code you are writing is for a new product that is still trying to find a market-fit spending a lot of time in the architecture of something that could drastically change doesn’t make much sense to me. All that I’m saying is that, as opposed to some other opinionated frameworks, react let’s you do pretty much whatever you want, which is great for speed development but can also exhausting in the huge amount of decisions that need to be made.
- leeoniya 6y ago> but if the code you are writing is for a new product that is still trying to find a market-fit spending a lot of time in the architecture of something that could drastically change doesn’t make much sense to me. "Nothing is more permanent than a temporary solution"
- mumblemumble 6y agoIt's true. But, after having witnessed, and having committed, countless acts of perfecting something until it died on the vine, I would consider, "This hack is hard to change because so very many people are paying us money in return for the privilege of relying on it," to be a very nice problem to have.
- leeoniya 6y agothe pendulum can swing too far in either direction. but pumping out features with no regard for how they will be maintained is a recipe for lower velocity and less stability in the future.
- _benj 6y agotrue, but for me writing highly architected features that take 3x or more time to write just to steer away because of business needs (i.e. doesn't sell) seems to me more painful.
- kilburn 6y agoMost people here are criticizing the author for doing some dumb things. I concur, but still think they have a good point. First, keep in mind that the author's use case is a content-heavy app with sprinkles of interactivity. This is very important because it sets the "webpage speed" goalpost to a concrete place: they want good lighthouse/first load times and good SEO. I've fallen into the same pit before. I've used Create React App with a custom server-renderer, Gatsby and Next in different projects. None of the solutions is truly satisfactory for the author's use case for a single very strong reason: React's hydration process is both blocking and slow. I hope that sooner rather than later React is able to offer a good solution for incremental hydration, but it seems quite far for now. Once you realize this, the only way to keep using React is to step out of the mainstream and play with multiple render roots, parts of the page that never get hydrated and so on. It is possible to do things here, but it is definitely a rocky path. Of course, there are many wrong things the author explains that you can avoid, but I'll throw a bone to them here too. Most "wrong things to do" they explain are both wrong and understandable. And they openly accept it. For instnace, one wrong thing to do that I've had to fight against a lot is JS-based device-specific rendering. It is so much easier to implement a "mobile ? <MobileScreen /> : <DesktopScreen />" than to make a single screen that adapts properly using CSS that it's not even funny. Unfortunately, it also breaks SSR, leads to janky page-loads and poor performance. I fully agree that as of today and for content-heavy sites React pushes you towards a pit of despair instead of a pit of success. You can make it work, but ... is it worth it?
- aphextron 6y agoIt's just apples and oranges. Web pages should never even consider using React. Maybe a bit of vanilla JS/jQuery here and there for whatever interactivity you need, and then server side rendering for the content. Building web applications on the other hand, has been revolutionized by the use of React. I would never seriously consider any other UI rendering library right now because of the sheer volume of support and active development around it and its' ecosystem. And hand rolling vanilla JS in a large scale web application quickly becomes a maintainability nightmare. The alternative of doing things old school with server side templates is ok, but it massively slows down your iteration speed through reliance on tight coupling between backend and frontend.
- recursivedoubts 6y agoThe initial motivation for intercooler.js (which the author forked) was performance. I was working on a large bulk table update and building the table dynamically in javascript. The performance was terrible (this was back in 2012, no idea what it would be like today). I realized that I could just deliver and slam HTML into the DOM and that the browser engine, written in C, was very fast at rendering it. That turned into a pretty big javascript function, which then turned into intercooler, which then turned into htmx: https://htmx.org https://htmx.org
- revscat 6y agoThis is amazing.
- Blackthorn 6y agoWow, that's awesome! Would have definitely made some stuff I've done a lot easier.
- JeremyNT 6y agoI love seeing more work in this space! This sounds similar to the approach Basecamp has taken, with tools like stimulus.js (combined with with Rails UJS and Turbolinks). You can make a really responsive page with normal server-side HTML templates that "sprinkle" in the ajax functionality. Tools like this feel very familiar to those of us who got started before the rise of the modern JS framework. It's kind of fun to see articles like the OP's pop up where people are rediscovering these techniques.
- recursivedoubts 6y agoYep. The problem is that HTML was never completed as a hypertext, they just kinda stopped at anchor tags and forms. There isn't a good reason that only anchors and forms should be able to specify HTTP requests. There isn't a good reason that only clicks or form submits should be able to trigger HTTP requests. There isn't a good reason that only POST and GET should be readily available (and POST only for forms.) And there isn't a good reason you should have to replace the whole page on every HTTP request, rather than a component within it. htmx is an attempt to complete HTML as a hypertext.
- leon_sbt 6y agoLike what some people said 5/100 on the page speed score is pretty bad. My site used to have this. It boiled down to two things that caused it. 1) I wasn't code splitting by page, and had a couple heavy dependencies (which made things worse) 2) I wasn't pre-rendering my create-react app via react-snap. Meaning during the CI build react-snap runs Puppeteer visits each page on the site, and generates ready-to-go html versions of each page. Those two changes took me from a 7/100 to a 95+/100 in short order. Makes logical sense too. Now a days the site hovers at 85/100. But I don't have the time right now to reinvestigate it. With the options at the time, I'm happy with my tech choices. If I had to start with React again today. I would do Next.JS with a static build output. Would save me a bunch of time scaffolding things.
- ceedan 6y agoThought this was a good read - and nice to see the progression of frustration with front-end development throughout the last decade, and then the introduction of mobile. This is a pretty common timeline for web devs who have been doing this ~10+ years. I wonder why the author did not contribute to intercooler rather than writing his own version. Would it really have been that difficult to avoid inheritance (or add an inheritance free api) and add batching to that library?
- piranha 6y agoBatching is doable. I even understand how to do it in htmx. The problem is that 1) htmx started later than I did 2) inheritance is like a plague, and I'd really want it to not exist I'll try to explain my stance. When you're a developer, you naturally drift to solutions which require you to write less or write faster. And inheritance certainly helps with that in simple cases. TwinSpark had inheritance up until we tried to implement sign-up/in logic. Damned popups... Anyway, that's the day we've killed inheritance: https://github.com/kasta-ua/twinspark-js/commit/5714ceea98364efc41bc4c9c7b9031c2b23cf2a4 https://github.com/kasta-ua/twinspark-js/commit/5714ceea9836... And if you have two APIs - with and without inheritance - developers will use the first one by default. And when it bites you it'll be painful. So if Carson reads my rant and decides to remove inheritance - I'll gladly move to htmx. If not - maintaining a library which is less than a thousand lines of code is not that big of a burden. :)
- ceedan 6y agoNice thanks for the details - I didn't know you were in talks with them about changes to intercooler, too. Nothing better than a nice pop-up to ruin your day... they're a different kind of plague
- seanwilson 6y agoWhy not a static site (i.e. JAMstack)? If it works for this use case, it can side step so many performance issues it feels like cheating.
- Demiurge 6y ago> It supports only modern browsers (not IE or Opera Mini) but drops that 88kb monster. Whenever I read this, I usually take it the author is being serious. However, how long does it actually take to load a 88kb library these days, is it really 'monstrous'? If this was the authors top performance drain based on profiling, I commend their technical abilities.
- piranha 6y agoWell, the reason why I started writing my own library is because I couldn't get all functionality I needed from Intercooler. Why it does not depend on jQuery? Because I wanted no dependencies. :-) And a "monster" is sarcasm referring to that React bundle I described before.
- atum47 6y agothe whole React thing got so ridiculous that you almost cannot call yourself a full stack developer if you don't use it on the front end.
- Shorel 6y agoIf anything should be learned from this article is this: "We need to look at it from two sides: if it’s good for developers and if it’s good for users." It is a pity this change in thinking required the pressure from Google Pare Rank, but now I see it as something very positive. Always remember: code is written once, and executed thousands or even millions of times. No optimization is worse than "premature optimization", and you probably misunderstand what "premature optimization" means anyway.
- piranha 6y agoHonestly, I now think that the main reason was different. I was fed up by my Macbook Pro's butterfly keyboard and started working on Macbook Air '15 again at the end of 2019. And in three months I was increasing annoyed by our site loading time. And then it hit me. MBA is not the slowest laptop out there. It is much worse for a large part of our users. This is where I started thinking we should jump off the hype ship. :-)
- deleted 6y ago[deleted]
- elliottkember 6y agoToday I threw away all the sockets in my set that weren't 14mm, because I only needed a 14mm socket.
- withinboredom 6y agoPart of me wants to create a hugo template that takes advantage of this (or htmx). You could make each "request" be a rendered snippet. :thinking: I may try this out.
- maitredusoi 6y agoI love the simplicity of Alpinejs, why bothering with old tech like React ;)
- dr-detroit 6y agocreate-react-app is inappropriate for anything but demos and quick and dirty throwaway stuff. that doesnt mean dont use react. it means dont expect to press 1 button and have a literal wizard make your application good.
- dreamcompiler 6y agoI've been doing Ajax practically since Day 1, and in the olden days when I was young and stupid I actually sent DIV IDs back to the server, which the server would then reply with -- in XML -- to tell the client which DIV to replace. Then I realized Javascript could do lexical closures which meant the client could keep track of the targets, which also meant the server no longer had to care about things servers shouldn't care about. The next realization was that DIV IDs are global variables and thus in most cases a bad idea, so now my event handlers automatically search upward (and sometimes sibling-wise) from 'this' for DIVs matching classes or other selectors, to keep the scope local. This TwinSpark library seems like the next iteration of all the good ideas, plus even more flexibility and proper separation of concerns, without JQuery or other dependencies. Bravo!
- whynotwhynot 6y ago"throwing away" and "jumping on the bandwagon" are two sides of the same problem: lack of forethought. If you take the time to adopt a technology and understand the pros and cons thoroughly you will not be doing any throwing away. You may end up not adopting the tech if its cons are not acceptable in your scenario but you wouldn't be adopting it then throwing it away. On HN, we see two extreme patterns: 1. Why we at $FAMOUS_COMPANY Switched to $HYPED_TECHNOLOGY https://saagarjha.com/blog/2020/05/10/why-we-at-famous-company-switched-to-hyped-technology/ https://saagarjha.com/blog/2020/05/10/why-we-at-famous-compa... 2. Why we dumped $HYPED_TECHNOLOGY (https://solovyov.net/blog/2020/a-tale-of-webpage-speed-or-throwing-away-react/ https://solovyov.net/blog/2020/a-tale-of-webpage-speed-or-th...) It's good entertainment (for some) but in the same way that mainstream media manufactures drama. :/
- jsguy 6y agoI think there are some interesting points here, though many (including the author) seem to forget: React is a UI library, not a framework. This means it is up to the user to decide and implement everything else, such as: * Code splitting * Loading of the code (at appropriate times, eg: ) * Any other optimisations I think the author simply failed to do this well and then blamed the library for their own shortcomings, and moved on to the 'next shiny thing'. There are plenty of patterns you can use to make your React app responsive, and many tools to help you achieve that, it's just a matter of being able to implement those tools effectively.
- z3t4 6y agoThe problem is how you think, and all frameworks is the same, they try to visualize the tree structure. The key to understanding async is to think of functions and state propagation.