Single page applications (SPAs) and Micro Frontends
Single page applications (SPAs) and Micro Frontends
https://developer.mozilla.org/en-US/docs/Glossary/SPA
An SPA (Single-page application) is a web app implementation that loads only a single web document, and then updates the body content of that single document via JavaScript APIs such as XMLHttpRequest and Fetch when different content is to be shown.
What does this mean? It means that when you enter some data on the forms in the UI screen and press a button, the entire page does not get refreshed.
Popular SPA frameworks
- React
- Angular
- Vue.JS
Benefits
- Don’t need to download more files as we move in the application - or as the user navigates in the website.
- If there are multiple html pages in the application, every single time the user navigates to a different page in the website, that html file needs to be downloaded.
- With React, everything is downloaded beforehand. When the user is navigating pages, there is nothing more to download.
- The whole application exists in javascript files in
src
folder.
Micro frontends
Divide a monolithic app into multiple, smaller apps.
Each smaller app is responsible for a distinct feature of the product.
Integrations
The container decides when/where to show each Microfrontend. So the container needs access to the source code (and the items) of all the micro frontends (e.g. Products list, Cart, etc.)
Different ways of implementing integration
- There are many different solutions, each have pros and cons
- No single perfect solution to integration
- Pick a solution based on your requirements
Categories of integration
- Build-time (compile-time) integration
- Before Container gets loaded in the browser, it gets access to ProductsList source code
- e.g. using packages as dependencies in another application
- Run-time (client-side) integration
- After Container gets loaded in the browser, it gets access to ProductsList source code
- e.g. instead of publishing code as an npm package, they deploy it to a server that can be accessed via a https url
- Advantages:
- Independent applications can be deployed independently
- Different live versions can be deployed simultaneously
- Disadvantages:
- Tooling and setup is more complicated
- Server integration
- While sending down JS to load up Container, a server decides on whether or not to include ProductsList source
Reading material
- https://en.wikipedia.org/wiki/Micro_frontend
- https://micro-frontends.org/
- https://martinfowler.com/articles/micro-frontends.html
- https://www.turing.com/blog/micro-frontends-what-are-they-when-to-use-them
Benefits
- Different components can be thought of as different applications
- Multiple engineering teams can work in isolation
- Each smaller app is easier to understand and make changes to
- Different teams can work on different components
- Different components can be built using different frameworks like React and Angular