Files
2nd/10_Wiki/Topics/DevOps_and_Security/Single Page Applications (SPA).md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

5.4 KiB

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

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

function navigate(url: string) {
  history.pushState({}, "", url);
  render(); // re-render based on location.pathname
}

window.addEventListener("popstate", render);

Code splitting — 매 route-level lazy

import { lazy, Suspense } from "react";

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

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

Data fetching — TanStack Query

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

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

location / {
  try_files $uri $uri/ /index.html;
}

Skeleton + optimistic UI

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

🤖 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 정리