SPA
Single Page Application
Web applications that work without page reloads. Implemented with React, Vue, and Angular.
Single Page Application
Web applications that work without page reloads. Implemented with React, Vue, and Angular.
SPA (Single Page Application) is a web application architecture that dynamically changes content through JavaScript within a single HTML page. Unlike the traditional MPA (Multi Page Application), it does not reload the entire page on page transitions, but fetches only the necessary data from the server and updates the DOM.
The core of an SPA is client-side routing. It uses the History API to change the URL while switching views without a page refresh. This provides a smooth user experience similar to a native app, and makes it easy to maintain state across pages.
Frameworks such as React, Vue, Angular, and Svelte are widely used for SPA development. They support efficient UI updates through a Virtual DOM or reactive systems, and improve code reusability with a component-based architecture.
Disadvantages of SPAs include a long initial loading time and being disadvantageous for SEO. To address this, code splitting, prerendering, and hybrid approaches with SSR (Next.js, Nuxt, etc.) have developed.
// React Routerλ₯Ό μ¬μ©ν SPA λΌμ°ν
import { BrowserRouter, Routes, Route, Link, useNavigate } from 'react-router-dom';
// λΌμ°ν° μ€μ
function App() {
return (
<BrowserRouter>
<nav>
<Link to="/">ν</Link>
<Link to="/about">μκ°</Link>
<Link to="/products">μ ν</Link>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/products" element={<Products />} />
<Route path="/products/:id" element={<ProductDetail />} />
<Route path="*" element={<NotFound />} />
</Routes>
</BrowserRouter>
);
}
// λμ λ€λΉκ²μ΄μ
function ProductCard({ product }) {
const navigate = useNavigate();
const handleClick = () => {
navigate(`/products/${product.id}`, {
state: { fromList: true }
});
};
return (
<div onClick={handleClick}>
<h3>{product.name}</h3>
</div>
);
}
// μ½λ μ€ν리ν
μΌλ‘ λ²λ€ μ΅μ ν
import { lazy, Suspense } from 'react';
const AdminDashboard = lazy(() => import('./AdminDashboard'));
function App() {
return (
<Suspense fallback={<Loading />}>
<Routes>
<Route path="/admin/*" element={<AdminDashboard />} />
</Routes>
</Suspense>
);
}
In a technical meeting:
"I heard the marketing team is worried about SEO, so let's solve it by applying SSR to our SPA. If we migrate to Next.js, most of the existing React code can be reused."
In a technical interview:
"Please explain the pros and cons of an SPA." - "The advantages are an app-like UX and fast page transitions. The disadvantages are the initial loading and SEO, which we address with code splitting and an SSR/SSG hybrid."
In a code review:
"This page is almost static, so I don't think we need to render it on the client. If we generate it at build time with getStaticProps, performance should get much better."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Cause: A large JavaScript bundle (2MB+) caused initial loading of over 10 seconds on a 3G connection
Impact: Mobile user bounce rate surged, failed to enter emerging markets
Resolution: Introduced Server Components, aggressive code splitting, and Critical CSS inlining
Lesson: Set a bundle size budget and integrate performance monitoring into the CI pipeline
Cause: Used only client-side rendering, so crawlers could not recognize the content
Impact: Disappeared from Google search results, organic traffic plummeted
Resolution: Migrated to Next.js and applied an SSR/SSG hybrid
Lesson: Always consider SSR/SSG for content sites, and choose a rendering strategy according to the nature of the app
Q1. What is the core technology that allows page transitions in an SPA to work without a full page refresh?
Q2. Which of the following is NOT an appropriate way to address the main disadvantages of an SPA?
Q3. What is the way to implement code splitting in React?
If this page has any errors or you would like to add something, please let us know!