Get the latest tech news

Using Rust Back End to Serve an SPA


In web development and deployment, most software engineers are familiar with either: Separating the built SPA and the backend (Client-Side Rendering), or Return HTML directly from the backend (Server-Side Rendering) I recently (re)discovered 1 that there is a third way: embedding the built SPA into the backend’s binary file, and serving it directly. I think this is an elegant approach, as the pros are: Simpler deployment as we only have one binary file in the end Simpler code where we don’t have to take into account CORS and the backend endpoint since the frontend and backend are served from the same origin 2 The cons are quite clear:

No matter how good is it, it’s still an unconventional approach; expect lots of push back from people Increased binary size and memory usage because of the static file embedding Slightly reduced DX due to no frontend hot reloading While the code that I’m going to show you is in that specific stack, I think it’s not challenging to adopt the mindset to other languages and frameworks and libraries . For simplicity, I’d start with a monorepo setup, where the backend and the frontend are in separate folders in the same Git repository.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of end

end

Photo of Rust

Rust

Photo of spa

spa

Related news:

News photo

Nova: A JavaScript and WebAssembly engine written in Rust

News photo

Elon Musk’s stint in the US government is coming to an end

News photo

Trump tariffs ruled illegal within minutes of Musk announcing end of government role