A comprehensive Next.js application demonstrating the differences between CSR, SSR, SSG, and Hybrid rendering strategies using real cryptocurrency data from the CoinGecko API.
- Real-time Cryptocurrency Data - Live prices, market caps, and charts
- Multiple Rendering Strategies - Compare CSR, SSR, SSG, and Hybrid approaches
- Performance Optimized - React Query for efficient data fetching and caching
- Responsive Design - Mobile-first design with dark mode support
- TypeScript - Full type safety throughout the application
- Educational Content - Each demo includes detailed explanations
- Use Case: Interactive dashboards, real-time data, personalized content
- Implementation: Data fetched on client after page load
- Benefits: Smooth interactions, reduced server load
- Trade-offs: Slower initial load, SEO challenges
- Use Case: SEO-critical pages, fresh data requirements
- Implementation: Data fetched on server for each request
- Benefits: Better SEO, faster perceived load time
- Trade-offs: Higher server load, slower page transitions
- Use Case: Content that doesn't change often, landing pages
- Implementation: Data fetched at build time
- Benefits: Fastest loading, excellent SEO, CDN cacheable
- Trade-offs: Stale data, requires rebuilds for updates
- Use Case: Complex applications requiring multiple strategies
- Implementation: Strategic combination of CSR, SSR, and SSG
- Benefits: Optimized for specific use cases
- Trade-offs: More complex implementation
- Next.js 14 - React framework with App Router
- TypeScript - Type safety and better developer experience
- Tailwind CSS - Utility-first CSS framework
- React Query - Server state management and caching
- Recharts - Chart library for data visualization
- Axios - HTTP client for API requests
- Lucide React - Icon library
-
Clone the repository
git clone <repository-url> cd my-app
-
Install dependencies
npm install
-
Start development server
npm run dev
-
Open in browser
http://localhost:3000
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
This project uses the CoinGecko API (free tier) to fetch cryptocurrency data:
- Market Data:
/coins/markets- List of cryptocurrencies with prices - Coin Details:
/coins/{id}- Detailed information about specific coins - Price History:
/coins/{id}/market_chart- Historical price data for charts
- Free tier: 10-50 calls/minute
- Implemented with request queuing and error handling
- Cached responses to minimize API calls
This application handles CoinGecko API rate limits (30 requests per minute) with several strategies:
- Request Delays: 3-second delays between API calls during build
- Retry Logic: Automatic retry with 30-second wait for rate-limited requests
- Fallback Data: Comprehensive fallback data for popular cryptocurrencies
- Sequential Processing: Build-time requests processed one at a time
- Build Timeout: Extended build timeout to accommodate delays
Add these to your Vercel deployment:
COINGECKO_API_DELAY=3000 # Delay between API calls (ms)
SSG_MAX_COINS=10 # Number of coins for SSG
NODE_ENV=production # Production optimizationsThe custom build script (scripts/build.js) automatically:
- Sets appropriate delays for production builds
- Retries with fewer coins if rate limited
- Provides detailed logging for debugging
- Environment Variables: Set in Vercel dashboard
- Build Command: Uses
npm run build(custom script) - Build Timeout: Automatically extended for API delays
- Fallback Strategy: Always has working data even if API fails
- Time to First Byte (TTFB): SSR fastest, then SSG, then CSR
- Largest Contentful Paint (LCP): SSG fastest, then SSR, then CSR
- First Input Delay (FID): CSR best (after hydration), others equal
- Cumulative Layout Shift (CLS): SSG best, others depend on implementation
- SSR/SSG: Content available in initial HTML
- CSR: Requires JavaScript execution for content
- Hybrid: Strategic rendering based on page importance
- SSG: Build-time caching, CDN distribution
- SSR: Server-side caching, revalidation strategies
- CSR: Client-side caching with React Query
- Hybrid: Multi-layered caching approach
src/
βββ app/ # Next.js App Router pages
β βββ layout.tsx # Root layout with providers
β βββ page.tsx # Landing page with strategy overview
β βββ loading.tsx # Global loading component
β βββ not-found.tsx # 404 page with helpful navigation
β βββ csr/ # Client-Side Rendering demo
β β βββ page.tsx # CSR cryptocurrency list
β β βββ coin/[id]/ # Dynamic CSR coin details
β βββ ssr/ # Server-Side Rendering demo
β β βββ page.tsx # SSR cryptocurrency list
β β βββ coin/[id]/ # Dynamic SSR coin details
β βββ ssg/ # Static Site Generation demo
β β βββ page.tsx # SSG cryptocurrency list
β β βββ coin/[id]/ # Dynamic SSG coin details
β βββ hybrid/ # Hybrid strategy demo
β β βββ page.tsx # Mixed rendering approaches
β βββ performance/ # Performance comparison page
β β βββ page.tsx # Detailed metrics and analysis
β βββ app/ # Full application example
β βββ page.tsx # Complete crypto dashboard
β βββ coin/[id]/ # Full-featured coin details
βββ components/ # Reusable React components
β βββ Navigation.tsx # Responsive nav with dark mode
β βββ Footer.tsx # Site footer with links
β βββ CryptoTable.tsx # Cryptocurrency data table
β βββ LoadingSpinner.tsx # Loading states and spinners
β βββ PriceChart.tsx # Recharts price visualization
β βββ StrategyCard.tsx # Strategy explanation cards
β βββ ErrorBoundary.tsx # Error handling component
βββ hooks/ # Custom React hooks
β βββ useCrypto.ts # React Query hooks for API calls
βββ lib/ # Utility functions and API client
β βββ api.ts # CoinGecko API integration
β βββ utils.ts # Formatting and utility functions
βββ providers/ # React context providers
β βββ QueryProvider.tsx # React Query configuration
βββ types/ # TypeScript type definitions
βββ crypto.ts # API response and component types
src/lib/api.ts- CoinGecko API integration with error handlingsrc/hooks/useCrypto.ts- React Query hooks for data fetchingsrc/components/Navigation.tsx- Responsive navigation with dark modesrc/providers/QueryProvider.tsx- React Query configurationsrc/types/crypto.ts- TypeScript definitions for API responses
npm run buildnpm run build && npm run export- Vercel - Optimized for Next.js, supports all rendering strategies
- Netlify - Good for SSG, limited SSR support
- AWS/Azure/GCP - Full control, requires more configuration
Each demo page includes performance metrics and explanations:
- Bundle Size: JavaScript payload delivered to client
- Cache Strategy: How data is cached and revalidated
- Hydration Time: Time for client-side JavaScript to become interactive
- Data Freshness: How current the displayed data is
- β Real-time cryptocurrency data from CoinGecko API
- β Multiple rendering strategies (CSR, SSR, SSG, Hybrid)
- β Responsive design with dark mode support
- β TypeScript for type safety
- β React Query for efficient data fetching
- β Interactive price charts with Recharts
- β Error handling and loading states
- β Performance comparison page
- β SEO optimization for different strategies
- β Mobile-first responsive design
- β Dark/light mode toggle with localStorage persistence
- β Smooth transitions and hover effects
- β Accessible navigation and components
- β Loading spinners and skeleton states
- β Error boundaries with helpful error messages
- β 404 page with navigation suggestions
- β API rate limiting and error handling
- β React Query caching and background updates
- β Static generation for top 50 cryptocurrencies
- β Server-side rendering with fresh data
- β Client-side rendering with real-time updates
- β Hybrid approach combining multiple strategies
Run the development server and visit different routes to see each rendering strategy in action:
/- Landing page with strategy explanations/csr- Client-side rendering demo/ssr- Server-side rendering demo/ssg- Static site generation demo/hybrid- Hybrid approach demo/performance- Performance comparison and metrics/app- Full application showcase
This project is for educational purposes and demonstrates modern web development practices with different rendering strategies.
Built with Next.js 14, TypeScript, React Query, and Tailwind CSS