This document outlines the implementation of Incremental Static Regeneration (ISR) for property detail pages in the PropChain FrontEnd application. This implementation addresses issue #136 by implementing caching and performance optimizations for property pages.
File: src/app/properties/[id]/page.tsx
- Converted from client component to server component
- Added ISR configuration with 60-second revalidation
- Implemented async data fetching on the server side
- Added proper TypeScript interfaces for props
- Created skeleton loading states for better UX
Key Features:
// ISR configuration - revalidate every 60 seconds
export const revalidate = 60;
async function PropertyDetailContent({ propertyId }: { propertyId: string }) {
const property = await getPropertyForISR(propertyId);
if (!property) {
notFound();
}
// ... render property content
}Server Component: src/components/PropertyDetailServer.tsx
- Handles static content rendering
- Displays property details, images, features
- No client-side interactivity
- Optimized for server-side rendering
Client Component: src/components/PropertyDetailClient.tsx
- Contains interactive elements (wallet connector, price alerts)
- Minimal client-side JavaScript
- Hydrates only the necessary interactive parts
Webhook Endpoint: src/app/api/revalidate/route.ts
Features:
- Secure webhook with HMAC-SHA256 signature verification
- Support for individual property revalidation
- Support for bulk property revalidation
- Proper error handling and logging
- Health check endpoint
Usage Examples:
# Revalidate single property
curl -X POST https://your-domain.com/api/revalidate \
-H "Content-Type: application/json" \
-H "x-webhook-signature: <signature>" \
-d '{
"type": "property",
"propertyId": "property-123",
"reason": "Property updated"
}'
# Revalidate all properties
curl -X POST https://your-domain.com/api/revalidate \
-H "Content-Type: application/json" \
-H "x-webhook-signature: <signature>" \
-d '{
"type": "all-properties",
"reason": "Bulk update"
}'File: src/app/properties/[id]/not-found.tsx
- Custom 404 page for missing properties
- Helpful messaging for new properties
- Navigation options for users
- Professional error handling
File: next.config.ts
Added optimized cache headers for property pages:
{
source: "/properties/:path*",
headers: [
{
key: "Cache-Control",
value: "public, max-age=60, stale-while-revalidate=300, s-maxage=300",
},
{
key: "Vary",
value: "Accept-Encoding",
},
],
}Cache Strategy:
max-age=60: Browser cache for 1 minutestale-while-revalidate=300: Serve stale content for 5 minutes while revalidatings-maxage=300: CDN cache for 5 minutes
File: src/lib/propertyServiceServer.ts
- Dedicated server-side property service
- ISR-specific data fetching functions
- Revalidation utilities
- Error handling for missing properties
- Every request triggered server-side rendering
- No caching of property pages
- Higher server load
- Slower response times
- Poor CDN utilization
- Pages cached for 60 seconds
- Background revalidation
- Significantly faster response times
- Better CDN utilization
- Reduced server load
- Improved user experience
All revalidation requests are logged with:
- Request type (single property or bulk)
- Property ID (if applicable)
- Reason for revalidation
- Timestamp
- Success/failure status
Monitor cache hit rates and revalidation frequency through:
- Next.js analytics
- CDN metrics
- Server logs
- HMAC-SHA256 signature verification
- Environment variable for webhook secret
- Request validation
- Rate limiting (recommended)
- No sensitive data in cached pages
- Proper cache headers for authenticated routes
- CDN security rules
# Webhook security
REVALIDATE_WEBHOOK_SECRET=your-secure-secret-key
# Next.js configuration
NEXT_PUBLIC_API_URL=https://your-domain.com- Configure CDN to respect cache headers
- Set up proper purging strategies
- Monitor cache performance
- Run development server
- Visit property pages
- Monitor revalidation behavior
- Test webhook endpoint
- Deploy to staging environment
- Test cache behavior
- Verify webhook functionality
- Monitor performance metrics
- Dynamic Revalidation Intervals: Different revalidation times based on property activity
- Smart Caching: Cache invalidation based on property updates
- Analytics Integration: Track cache performance
- A/B Testing: Compare ISR vs SSR performance
- Edge Functions: Deploy revalidation logic to edge
- Cache hit rates
- Revalidation frequency
- Performance metrics
- Error rates
-
Pages Not Updating
- Check webhook configuration
- Verify revalidation endpoint
- Monitor server logs
-
Cache Issues
- Verify CDN configuration
- Check cache headers
- Clear cache if needed
-
Build Errors
- Ensure all dependencies are installed
- Check TypeScript configuration
- Verify component exports
# Check Next.js build
npm run build
# Test webhook locally
curl -X GET http://localhost:3000/api/revalidate
# Monitor logs
tail -f logs/next.logThis ISR implementation provides significant performance improvements for property pages while maintaining data freshness and providing a robust revalidation system. The implementation follows Next.js best practices and includes proper error handling, security measures, and monitoring capabilities.