Insights:Page Caching and CDN Upgrade Order: What Comes First
Step 0: Measure Baseline First
Record:
- TTFB for homepage, category pages, detail pages, and form pages.
- Static asset sizes and counts.
- Database slow queries.
- Cache hit rate and origin fetch ratio.
Without a baseline, none of the later "faster" claims can be proven.
Step 1: Static Asset Caching
Start with images, CSS, JS, and fonts:
- Include version or hash in filenames.
- Set long cache expiration.
- Compress and optimize dimensions.
- Don't cache entry files that change often.
This step carries low risk and delivers direct gains.
Step 2: Page Caching
Select cacheable pages:
- Article pages, category pages, and product intro pages.
- Pages that don't depend on login or personalization.
- Pages with clear invalidation criteria.
Roll out slowly and monitor:
- Cache hit rate.
- Whether stale content appears.
- Whether forms and comments still work.
- Whether published changes take effect immediately.
Step 3: CDN Edge Caching
Add static assets first, then cacheable HTML. Configure clearly:
- Which paths are cached.
- Which cookies or parameters affect caching.
- Origin fetch ratio.
- Purge methods.
Don't cache the admin panel, shopping cart, or payment pages right away.
Step 4: Cache Invalidation
Publishing, price changes, and inventory updates must trigger invalidation:
- Purge by individual URL.
- Purge by tag or directory.
- Set reasonable TTLs.
- Keep a manual origin-fetch fallback.
A cache that can't be invalidated is more dangerous than no cache at all.
Step 5: Origin Traffic & Rate Limiting
When CDN origin requests spike, the origin server can be overwhelmed:
- Set origin request concurrency limits.
- Warm up hot content.
- Coordinate origin caching with CDN caching.
- Monitor origin bandwidth and 5xx errors.
Step 6: Verify
- Re-test TTFB from the same region and network.
- Compare cache hit rates.
- Check login, form submission, and payments.
- Monitor error rate over 24 hours.
Common Mistakes
- Using the same long cache policy for HTML and static assets.
- Caching user-specific (authenticated) content.
- Skipping CDN purge after deployment.
- Only checking the CDN console while ignoring origin logs.
- Changing too many layers at once, making it hard to isolate problems.
One-Sentence Principle
Static first, then page-level cache, then CDN; start with a limited scope before rolling out site-wide; every layer must support invalidation, rollback, and measurable outcomes.
Related Reading: