Overview
Simon Willison explains how to add dynamic features to websites that use aggressive caching. His blog sits behind Cloudflare with 15-minute cache headers but still supports client-side personalization without breaking the cache.
The Breakdown
- localStorage-based conditional display - Uses JavaScript to check for an ‘ADMIN’ key in localStorage and dynamically shows edit links only to the site owner, bypassing server-side authentication
- Client-side comment counting - Fetches comment counts from a separate JSON endpoint and updates the cached page display without invalidating the main page cache
- Cache-friendly architecture - Separates static content (cached for 15 minutes) from dynamic data (fetched separately), allowing the site to handle traffic spikes while still providing personalized features
- Progressive enhancement pattern - Pages work fully without JavaScript but gain additional functionality when JS is enabled, maintaining accessibility and performance