Skip to main content

What modern frontends need

Before we look at the tools, it helps to know how frontend development got so complicated in the first place, and what problems we actually need to solve.

A short history

Server-rendered HTML

Web apps used to work like this: the browser asks for a page, the server builds the HTML and sends it back. Click a link or submit a form, and you get a whole new page.

On the left, a Browser box holding a Page. On the right, a Server box labelled builds the whole page. An arrow labelled click a link or submit a form goes from the Page to the Server, and an arrow labelled a whole new HTML page comes back to the Page.
Figure 1: The server does all the work: every click sends a request, and the server sends back a whole new page.

This was simple. All the logic lived on the server, in one codebase. But every interaction meant a full page reload, and users wanted something that felt more interactive.

jQuery and AJAX

jQuery made it easy to send requests in the background (AJAX) and update bits of the page without a reload.

A Browser box holds a Page (the DOM) and a jQuery code box labelled event handlers. An arrow labelled event goes from the Page to the jQuery code, and an arrow labelled update the DOM goes back. Outside the browser, a Server box labelled JSON API. An arrow labelled AJAX request goes from the jQuery code to the Server, and an arrow labelled JSON comes back.
Figure 2: jQuery code in the browser sits between the page and the server: it handles events, asks the server for JSON, and updates the DOM by hand.

This worked well for small things. But as pages got more interactive, the code turned into a tangle of event handlers and DOM updates. It was hard to keep track of what was on the page, and why.

It also changed the backend. Instead of just rendering HTML, the server now needed API endpoints that serialised data to JSON for the frontend to use. And the frontend code had to know exactly what shape that JSON would be in. Change a field name on the backend, and the frontend could quietly break. Keeping the two in sync became an ongoing chore.

Debugging and testing got harder too. If something went wrong on the page, it could be many things: the backend logic, the serialisation, the request, the JavaScript that handled the response, or the code that updated the page.

Frameworks like Angular

Frameworks like AngularJS brought structure. The page was now an app running in the browser, with its own data, templates and logic.

A Browser box holds a Page and an Angular app box, which contains three smaller boxes: Data, Templates and Logic. An arrow labelled events goes from the Page to the app, and an arrow labelled render goes back. Outside the browser, a Server box labelled JSON API. An arrow labelled fetch data goes from the app to the Server, and an arrow labelled JSON comes back.
Figure 3: The app now lives in the browser, with its own data, templates and logic. The server just serves JSON.

React and components

React introduced the idea of building the UI out of components: small, reusable pieces that each render themselves based on their data. When the data changes, the component re-renders.

This was a genuinely good idea, and it’s a big part of why React became so popular.

The web platform racing to keep up

Meanwhile, browsers and JavaScript itself were changing fast. New language features came out, but not every browser supported them.

So developers started writing modern JavaScript (and later TypeScript) and using tools to transpile it into older JavaScript that every browser could run. Add bundlers, minifiers and package managers, and you now have a build pipeline just to get your code into the browser.

Two code boxes on the left: Frontend code (TypeScript, Sass) at the top and Backend code (Python) at the bottom. Frontend code feeds two rows. The Frontend test pipeline runs Linter, Type checker, Unit tests, then Browser tests. The Frontend build pipeline runs Transpiler, Bundler, Minifier, then Browser. Backend code also feeds two rows. The Backend build pipeline runs Install packages, Build image, Deploy, then Server. The Backend test pipeline runs Linter, Type checker, Unit tests, then API tests. In the middle on the right, an Integration tests box has an arrow coming down from Browser and an arrow coming up from Server.
Figure 4: The frontend and the backend each have their own build and test pipelines, and integration tests are needed to check that the two work together.

CSS couldn’t keep up either. Styling a big app with plain CSS got messy, so preprocessors, CSS-in-JS libraries and CSS frameworks appeared too.

The cost of all this

Each of these tools solved a real problem. But together they add up.

  • Frontend became its own specialty. You now need frontend engineers who know the framework, the build tools, and the ecosystem around them.
  • Two codebases. There’s a backend and a separate frontend app, each with its own language, dependencies, tests and deployment.
  • Three kinds of tests. You need frontend tests for your React components, backend tests for your API, and integration tests to check the two actually work together. Each uses different tools, different languages and a different way of thinking.
  • APIs everywhere. The frontend and backend talk through a JSON API. That’s another layer to design, build, document and keep in sync.
  • Complicated teams. A fullstack developer needs a huge range of skills. So teams usually split into frontend and backend developers, and someone has to coordinate the handoffs between them.
  • Slow going, even for unicorns. Say you’re one of those rare fullstack developers who knows both Python and a modern frontend framework well. You still have to wire everything up: build the endpoint, serialise the data, fetch it on the frontend, and keep both sides in sync. And you’re constantly switching between two codebases that see the world in different ways, with different languages, idioms, architectures and project structures. Even with all the skills, building a feature this way is slow.

Fullstack frameworks like Next.js

Frameworks like Next.js try to solve the two-codebase problem by turning frontend engineers into fullstack engineers. Your React code and your server code live in the same project.

They also add modern features like server-side rendering (SSR), where the server builds the HTML before sending it to the browser. Funnily enough, SSR used to be the only way to build a web app. We’ve come full circle.

But this adds its own complexity. Unless you look carefully, it’s hard to tell where a piece of code actually runs. Is it on the server? In the browser? At build time? Or some mix of the three?

A lot of clever machinery works behind the scenes to make this feel smooth. The developer experience can be nice, but you lose clarity. Things aren’t explicit, and when something goes wrong, you have to understand the magic to fix it.

Problem, solution, problem, solution…

Look at the pattern:

Four boxes climbing like a staircase from bottom left to top right: Problem, Complicated solution, New problem, Another complicated solution. An arrow steps up from each box to the next, and a last arrow steps up from Another complicated solution to an ellipsis, showing the climb carries on.
Figure 5: Every solution brings a new problem, which gets solved with yet another complicated solution.

Every time a new problem came up, a new solution was layered on top. Nothing was taken away.

That’s normal. When people face a problem, they tend to solve it by adding something. Removing things and simplifying is a much less common instinct.

What would the Zen of Python say?

If you write Python, you’ve probably seen the Zen of Python (try import this). It’s a list of guiding principles for writing good code. The modern frontend stack breaks quite a few of them.

Simple is better than complex.

A typical stack has a framework, a router, a state management library, a data-fetching library, a bundler, a transpiler and a CSS toolchain. That’s a lot of moving parts just to show a page.

Complex is better than complicated.

Some complexity is unavoidable. But much of today’s complexity isn’t needed by the app. It’s left over from layering one solution on top of another.

Explicit is better than implicit.

In frameworks like Next.js, it’s often unclear where code runs or when it runs. Build tools quietly rewrite your code before it reaches the browser.

Flat is better than nested.

Layers of components, providers, hooks and wrappers can make it hard to follow what happens when a user clicks a button.

There should be one– and preferably only one –obvious way to do it.

There are many ways to fetch data, manage state and style things, and the “right” way keeps changing. Each project picks a different combination.

If the implementation is hard to explain, it’s a bad idea.

Try explaining to a junior developer everything that happens between saving a file and seeing the change in the browser. Or how data gets from the database to the screen.

Readability counts.

When logic is spread across a backend, an API and a frontend app, you have to read three places to understand one feature.

Thinking from first principles

So let’s step back. Forget about the tools for a moment. What does a modern frontend actually need to do?

  • Render HTML. In the end, the browser shows HTML.
  • React to events. Clicks, typing, form submissions, and so on.
  • Send data to the backend. Save things, load things.
  • Re-render parts of the page when needed. Without reloading the whole thing.
  • Sometimes, show live updates sent by the backend. For example, a new message arriving.
  • Sometimes, manage a bit of state in the browser. For example, whether a dropdown is open.

That’s a much shorter list than the stack we ended up with.

What if HTML was just good enough?

What if we cut away the complexity and made HTML itself capable of doing these things?

That’s the idea behind HTMX and Alpine.js. They add a few small attributes to HTML:

  • HTMX lets any element send a request to the server and swap the HTML it gets back into the page.
  • Alpine.js handles the small bits of behaviour and state that live in the browser.

This means you can go back to rendering HTML on the server, the old-school way, with one codebase and no build step. And you still get a page that feels interactive.