I'm trying to figure out whether I should go for a Single Page Application (SPA) or a Multi-Page Application (MPA), especially when considering frameworks like Vue and HTMX. My understanding is that an MPA generally can't be hosted as a static site since it needs page layouting and composition. If the server is serving these pages, it seems like security can be better managed on the server side too. So, I'd like to know in which scenarios I should definitely opt for a Multi-Page Application rather than a SPA?
5 Answers
One drawback of SPAs is that they can create issues with links and bookmarks. Often, you can't easily open links in new tabs or bookmark different pages without navigating through the index. Plus, they can seem slower since you're constantly waiting for spinners when the server is rendering content.
If your application is primarily static, MPAs are the way to go, especially if simplicity is a priority and you want to avoid the complexities that come with JavaScript. I even wrote a blog post discussing the trade-offs between SPAs and MPAs, emphasizing that with MPAs, JavaScript adds features rather than being the foundation. In contrast, SPAs heavily depend on JavaScript and can feel more complex.
Scaling is a critical reason to go with MPAs. If your app is going to grow into a platform, breaking it into multiple pages can help manage complexity. Sure, SEO is a concern too, as basic SPAs can struggle with indexing since they often only serve the same HTML. Organizations with in-house devs usually find MPAs to work better for them.
From my experience, SPAs can handle large and complex sites, but they often require careful state management when navigating between pages, which can get tricky and lead to errors. I personally prefer MPAs because I don’t have to deal with the obsolete state of the app. Also, good old query parameters can make a big difference; just love that every page's state can be reproduced with a URL for the users.
While it's true that MPAs can be hosted as static sites by generating and uploading files, I lean towards MPAs because they have fewer client-side dependencies. This means that your page content won’t rely on client-side state and can be easily reloaded. However, SPAs do have their perks, like faster loading times and persistent state across navigations, which can be beneficial for features like media players or live chats. But with the new View Transitions API, MPAs are catching up in terms of providing smooth transitions.

Related Questions
How to Build a Custom GPT Journalist That Posts Directly to WordPress
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads