Course contentsShow
← React
Lesson 1806 of 2,39642. Data Fetching LibrariesFree lesson

SWR vs TanStack Query: Bundle Size and Simplicity

Comparing the minimal API surface and smaller bundle of SWR against TanStack Query's more comprehensive feature set.

SWR vs TanStack Query: Bundle Size and Simplicity

What you'll learn: How SWR's minimalist design and smaller bundle size compare to TanStack Query's feature-rich but heavier approach.

The Core Tradeoff

Both libraries solve data fetching, but they take different philosophical paths. SWR is the lightweight minimalist—it does one thing exceptionally well (stale-while-revalidate) with a tiny API surface. TanStack Query is the comprehensive toolkit—it handles complex scenarios out of the box but brings more code along.

Bundle Size Reality

SWR weighs in at approximately 4-5 KB gzipped, while TanStack Query is closer to 12-13 KB gzipped. That's nearly 3x the difference. For most apps this doesn't matter, but if you're building for bandwidth-constrained environments or have strict performance budgets, SWR's footprint advantage is real.

API Surface Comparison

SWR's API is intentionally small: one primary hook (useSWR), a few global config options, and a mutation helper. You learn it in an afternoon. TanStack Query offers useQuery, useMutation, useInfiniteQuery, query invalidation, optimistic updates, prefetching, hydration, and extensive configuration—dozens of options and patterns.

When Does This Matter?

If your data needs are straightforward—fetching, caching, revalidating—SWR's simplicity means less to learn, less to configure, and faster iteration. If you need advanced features like pagination, complex cache invalidation strategies, optimistic updates, or fine-grained control, TanStack Query provides them without custom solutions.

Think of it like choosing between a Swiss Army knife (SWR: essential tools, ultra-portable) versus a full toolbox (TanStack Query: tool for every job, heavier to carry).

Key Takeaway: SWR wins on bundle size (~4KB vs ~13KB) and API simplicity, making it ideal for straightforward use cases; TanStack Query's larger footprint buys you comprehensive features for complex data requirements.