| 1 | --- |
| 2 | title: "A Real World React -> htmx Port" |
| 3 | description: "David Guillot at Contexte gave what we are calling 'The Mother of All htmx Demos' at DjangoCon 2022. This essay summarizes this real-world case study of replacing React with htmx in a SaaS product, demonstrating significant improvements in code size, performance, and development team efficiency through the adoption of a hypermedia-driven architecture." |
| 4 | created: 2022-09-29 |
| 5 | modified: 2022-10-15 |
| 6 | authors: ["Carson Gross"] |
| 7 | tags: ["case-studies"] |
| 8 | --- |
| 9 | |
| 10 | It is all well and good talking about [REST & HATEOAS](/essays/hateoas) in theory or describing the |
| 11 | [Hypermedia-Driven Application](/essays/hypermedia-driven-applications) architecture, but, at the end of the day, what |
| 12 | matters in software is practical: Does it work? Does it improve things? |
| 13 | |
| 14 | We can say for sure that htmx _works_, since we use it in our own software. But it is hard to say that it would be |
| 15 | an _improvement_ over other approaches, since we haven't had an apples-to-apples comparison of how htmx might compare |
| 16 | with, |
| 17 | say, [react](https://reactjs.org/). |
| 18 | |
| 19 | Until now. |
| 20 | |
| 21 | [David Guillot](https://github.com/David-Guillot) at [Contexte](https://www.contexte.com/) has given what we are calling |
| 22 | ["The Mother of All htmx Demos"](https://en.wikipedia.org/wiki/The_Mother_of_All_Demos) at |
| 23 | [DjangoCon 2022](https://pretalx.evolutio.pt/djangocon-europe-2022/talk/MZWJEA/): |
| 24 | |
| 25 | > **From React to htmx on a real-world SaaS product: we did it, and it's awesome!** |
| 26 | > |
| 27 | > We took the plunge and replaced the 2-year-of-work React UI of our SaaS product with simple Django templates and htmx |
| 28 | > in a couple of months. We’d like to share our experience with you, with concrete indicators on various aspects, and |
| 29 | > convince your CTO! |
| 30 | |
| 31 | ## Video |
| 32 | |
| 33 | You can (should!) watch the entire presentation here: |
| 34 | |
| 35 | <iframe style="max-width: 100%" width="618" height="352" src="https://www.youtube.com/embed/3GObi93tjZI" title="DjangoCon 2022 | From React to htmx on a real-world SaaS product: we did it, and it's awesome!" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> |
| 36 | |
| 37 | ## Executive Summary |
| 38 | |
| 39 | * The effort took about **2 months** (with a 21K LOC code base, mostly JavaScript) |
| 40 | * **No reduction** in the application's user experience (UX) |
| 41 | * They reduced the **code base size** by **67%** (21,500 LOC to 7200 LOC) |
| 42 | * They _increased_ **python code** by **140%** (500 LOC to 1200 LOC), a good thing if you prefer python to JS |
| 43 | * They reduced their total **JS dependencies** by **96%** (255 to 9) |
| 44 | * They reduced their **web build time** by **88%** (40 seconds to 5) |
| 45 | * **First load time-to-interactive** was reduced by **50-60%** (from 2 to 6 seconds to 1 to 2 seconds) |
| 46 | * **Much larger data sets were possible** when using htmx, because react simply couldn't handle the data |
| 47 | * Web application **memory usage** was reduced by **46%** (75MB to 45MB) |
| 48 | |
| 49 | ## Analysis |
| 50 | |
| 51 | These are eye-popping numbers, and they reflect the fact that the Contexte application is extremely amenable to |
| 52 | hypermedia: it is a content-focused application that shows lots of text and images. We would not expect every |
| 53 | web application to see these sorts of numbers. |
| 54 | |
| 55 | However, we _would_ expect _many_ applications to see dramatic improvements by adopting the hypermedia/htmx approach, at |
| 56 | least for part of their system. |
| 57 | |
| 58 | ### Dev Team Makeup |
| 59 | |
| 60 | One easy-to-overlook aspect of the port is the effect it had on the team's structure. When Contexte was using react, |
| 61 | there was a hard split between back-end and front-end, with two developers being entirely back-end, one developer being |
| 62 | entirely front-end, and one developer being "full stack". |
| 63 | |
| 64 | ("Full stack" here means they are comfortable doing work on both the front-end and back-end, and, thus are able to |
| 65 | develop features entirely independently across the whole "stack".) |
| 66 | |
| 67 | After the port to htmx, *the entire team* became "full stack" developers. This means that each team member is more |
| 68 | effective and able to contribute more value. It also makes development more fun, since developers can own an entire |
| 69 | feature. Finally, it can lead to better optimized software, since the developer can make optimizations anywhere in |
| 70 | the stack without needing to coordinate with other developers. |
| 71 | |
| 72 | ## Slides |
| 73 | |
| 74 | The slides for the presentation can be found here (be sure to check the excellent speakers notes!) |
| 75 | |
| 76 | <https://docs.google.com/presentation/d/1jW7vTiHFzA71m2EoCywjNXch-RPQJuAkTiLpleYFQjI/edit?usp=sharing> |