Skip to content

nrahmatk/rendering-test

Repository files navigation

Cryptocurrency Website - Rendering Strategies Demo

A comprehensive Next.js application demonstrating the differences between CSR, SSR, SSG, and Hybrid rendering strategies using real cryptocurrency data from the CoinGecko API.

πŸš€ Features

  • 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

πŸ—οΈ Architecture

Rendering Strategies Demonstrated

1. CSR (Client-Side Rendering) - /csr

  • 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

2. SSR (Server-Side Rendering) - /ssr

  • 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

3. SSG (Static Site Generation) - /ssg

  • 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

4. Hybrid - /hybrid

  • 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

πŸ“¦ Tech Stack

  • 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

πŸ”§ Installation

  1. Clone the repository

    git clone <repository-url>
    cd my-app
  2. Install dependencies

    npm install
  3. Start development server

    npm run dev
  4. Open in browser

    http://localhost:3000
    

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

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.

πŸ“– API Integration

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

Rate Limiting

  • Free tier: 10-50 calls/minute
  • Implemented with request queuing and error handling
  • Cached responses to minimize API calls

πŸ”§ API Rate Limiting & Build Optimization

This application handles CoinGecko API rate limits (30 requests per minute) with several strategies:

Rate Limiting Solutions

  1. Request Delays: 3-second delays between API calls during build
  2. Retry Logic: Automatic retry with 30-second wait for rate-limited requests
  3. Fallback Data: Comprehensive fallback data for popular cryptocurrencies
  4. Sequential Processing: Build-time requests processed one at a time
  5. Build Timeout: Extended build timeout to accommodate delays

Environment Variables

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 optimizations

Build Optimization

The 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

Vercel Deployment

  1. Environment Variables: Set in Vercel dashboard
  2. Build Command: Uses npm run build (custom script)
  3. Build Timeout: Automatically extended for API delays
  4. Fallback Strategy: Always has working data even if API fails

🎯 Learning Objectives

Performance Comparison

  • 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

SEO Considerations

  • SSR/SSG: Content available in initial HTML
  • CSR: Requires JavaScript execution for content
  • Hybrid: Strategic rendering based on page importance

Caching Strategies

  • SSG: Build-time caching, CDN distribution
  • SSR: Server-side caching, revalidation strategies
  • CSR: Client-side caching with React Query
  • Hybrid: Multi-layered caching approach

πŸ“ Project Structure

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

πŸ” Key Files

  • src/lib/api.ts - CoinGecko API integration with error handling
  • src/hooks/useCrypto.ts - React Query hooks for data fetching
  • src/components/Navigation.tsx - Responsive navigation with dark mode
  • src/providers/QueryProvider.tsx - React Query configuration
  • src/types/crypto.ts - TypeScript definitions for API responses

πŸš€ Deployment

Build for Production

npm run build

Static Export (for SSG pages)

npm run build && npm run export

Deployment Platforms

  • Vercel - Optimized for Next.js, supports all rendering strategies
  • Netlify - Good for SSG, limited SSR support
  • AWS/Azure/GCP - Full control, requires more configuration

πŸ“Š Performance Metrics

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

🎨 Features Implemented

Core Features

  • βœ… 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

UI/UX Features

  • βœ… 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

Technical Features

  • βœ… 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

πŸ§ͺ Testing

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

πŸ”— External Resources

πŸ“ License

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

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published