Overview
Simon Willison explains how to add dynamic features to websites with aggressive caching by using client-side techniques that bypass server-side rendering. His blog uses 15-minute Cloudflare caching but still displays personalized admin controls and real-time visitor counts.
The Breakdown
- localStorage-based conditional rendering - JavaScript checks for an ‘ADMIN’ key in localStorage to show edit links only to the site owner, avoiding server-side authentication checks
- Client-side admin URL generation - Edit buttons are dynamically created using data attributes that contain Django admin URLs, allowing quick content editing without cache invalidation
- Real-time visitor analytics with GoatCounter - Uses a third-party analytics service that displays live visitor counts via JavaScript, providing fresh data despite aggressive page caching
- Hybrid caching strategy - Combines server-side full-page caching for performance with client-side JavaScript for personalization, enabling both speed and dynamic functionality