---
id: wiki-2026-0508-single-page-applications-spa
title: Single Page Applications (SPA)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [SPA, Single-Page App, Client-Side App]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [web, frontend, architecture, routing]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: TypeScript
  framework: React/Vue/SvelteKit
---

# Single Page Applications (SPA)

## 매 한 줄
> **"매 한 HTML 의 모든 view 의 client-side 의 render"**. SPA 매 initial load 후 server-fetch 의 X 의 navigation — 매 data-only API call. 2026 매 SPA-only 의 declining trend — 매 SSR/RSC hybrid (Next.js 15, Remix, Astro Islands) 의 mainstream.

## 매 핵심

### 매 핵심 Architecture
- 매 single `index.html` shell.
- 매 JS bundle 의 view rendering (React / Vue / Svelte).
- Client-side routing (History API).
- 매 API 의 JSON fetch — REST / GraphQL / tRPC.

### 매 Pros
- 매 fluid navigation — 매 page reload X.
- 매 rich interactivity.
- 매 backend / frontend 분리 — 매 separate deploy.

### 매 Cons
- Initial bundle size — 매 large.
- SEO 의 challenge — 매 crawler 의 JS execution 의존.
- TTI (Time to Interactive) 의 slow.
- 매 JS-disabled / network-fail 의 blank screen.

### 매 vs MPA / SSR / SSG
- MPA: server 의 매 page-by-page render.
- SSR: 매 first render 의 server, 매 hydrate 후 SPA-like.
- SSG: 매 build-time 의 pre-render — 매 static deploy.
- RSC (React Server Components): 매 server/client 의 component-level mix.

### 매 2026 trend
- 매 pure SPA 의 niche (admin panel, internal tool).
- Next.js / Remix / SvelteKit 의 hybrid 의 default.
- Astro Islands — 매 partial hydration.
- 매 streaming SSR + Suspense — 매 perceived perf 개선.

## 💻 패턴

### React Router v7 — 매 client-side routing
```tsx
import { createBrowserRouter, RouterProvider } from "react-router";

const router = createBrowserRouter([
  { path: "/", element: <Home /> },
  { path: "/posts/:id", element: <Post />, loader: postLoader },
  { path: "*", element: <NotFound /> },
]);

export default function App() {
  return <RouterProvider router={router} />;
}
```

### History API — manual SPA navigation
```typescript
function navigate(url: string) {
  history.pushState({}, "", url);
  render(); // re-render based on location.pathname
}

window.addEventListener("popstate", render);
```

### Code splitting — 매 route-level lazy
```tsx
import { lazy, Suspense } from "react";

const Dashboard = lazy(() => import("./Dashboard"));

<Suspense fallback={<Spinner />}>
  <Dashboard />
</Suspense>
```

### Data fetching — TanStack Query
```typescript
import { useQuery } from "@tanstack/react-query";

function Post({ id }: { id: string }) {
  const { data, isLoading } = useQuery({
    queryKey: ["post", id],
    queryFn: () => fetch(`/api/posts/${id}`).then(r => r.json()),
    staleTime: 60_000,
  });

  if (isLoading) return <Skeleton />;
  return <Article {...data} />;
}
```

### Vite — SPA build
```typescript
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ["react", "react-dom"],
          ui: ["@radix-ui/react-dialog"],
        },
      },
    },
  },
});
```

### SPA fallback — server config (nginx)
```nginx
location / {
  try_files $uri $uri/ /index.html;
}
```

### Skeleton + optimistic UI
```tsx
const mutation = useMutation({
  mutationFn: postComment,
  onMutate: async (newComment) => {
    await queryClient.cancelQueries({ queryKey: ["comments"] });
    const prev = queryClient.getQueryData(["comments"]);
    queryClient.setQueryData(["comments"], (old: any) => [...old, newComment]);
    return { prev };
  },
  onError: (_, __, ctx) => queryClient.setQueryData(["comments"], ctx.prev),
});
```

## 매 결정 기준
| 상황 | Approach |
|---|---|
| Public marketing site | SSG (Astro / Next static) — 매 SPA X. |
| Content blog | SSG / ISR. |
| SaaS dashboard (auth-walled) | SPA OK — 매 SEO 의 X 필요. |
| E-commerce | SSR/RSC — 매 SEO + perceived perf. |
| Internal admin tool | SPA — Vite + React Router. |
| Rich realtime app | SPA + WebSocket. |

**기본값**: 매 새 project 의 Next.js / Remix / SvelteKit (hybrid). 매 pure SPA 의 internal tool 만.

## 🔗 Graph
- 부모: [[Web Architecture]]
- 변형: [[MPA]] · [[SSR]] · [[SSG]] · [[Islands Architecture]]
- 응용: [[SvelteKit]]
- Adjacent: [[Code Splitting]] · [[Hydration]] · [[Service Worker]]

## 🤖 LLM 활용
**언제**: 매 auth-walled rich app — admin, dashboard, realtime collaborative tool.
**언제 X**: 매 SEO-critical / content-heavy site — 매 SSR/SSG 의 사용.

## ❌ 안티패턴
- **매 SEO-critical site 의 pure SPA**: 매 crawler 문제 → SSR/SSG.
- **매 huge initial bundle (no code-split)**: TTI 악화.
- **매 in-memory routing 의 history API X**: 매 back-button 의 X.
- **매 server fallback (try_files) 의 X**: 매 deep-link refresh 의 404.
- **매 every state 의 Redux**: 매 over-engineering — TanStack Query + local useState.

## 🧪 검증 / 중복
- Verified (MDN Web Docs, React Router v7 docs).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — SPA arch + 2026 hybrid trend 정리 |
