🌐 Web Development

SPA

Single Page Application

Web applications that work without page reloads. Implemented with React, Vue, and Angular.

πŸ“– Detailed Explanation

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.

πŸ’» Code Example

// 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>
  );
}

πŸ—£οΈ Examples of Practical Conversations

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

⚠️ Cautions

πŸ”— Related Terms

SSR SSG Virtual DOM React Hydration

πŸ”₯ Real-World Incidents

Airbnb 2017

Increased bounce rate due to SPA initial loading time

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

General Case Common

Search traffic dropped 70% due to SEO issues

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

πŸ“ Comprehension Quiz

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?

πŸ“š Learn More

πŸ’¬ Questions & Contributions

If this page has any errors or you would like to add something, please let us know!