Cache Busting System

This document explains the cache busting system implemented to resolve aggressive browser caching issues.

Problem

The website was experiencing strong caching issues, particularly in Brave browser, where users were seeing older versions of the site even after updates were deployed.

Solution

We implemented a multi-layered cache busting system:

1. Dynamic Version Parameters

All CSS and JavaScript files now use dynamic version parameters based on Jekyll’s build time:

<!-- Before -->
<link rel="stylesheet" href="/css/main.css?v=20250904t">
<script src="/js/app.js?v=20250904c"></script>

<!-- After -->
<link rel="stylesheet" href="/css/main.css?v=20250916032840">
<script src="/js/app.js?v=20250916032840">

2. Reduced Cache Headers

Updated _headers file to use more reasonable cache durations:

3. Client-Side Cache Detection

Added js/cache-buster.js that:

4. Cache Version Meta Tag

Added meta tag to track cache version:

<meta name="cache-version" content="20250916032840">

5. Deployment Scripts

Created utility scripts for managing cache versions:

Usage

Every time the site is built/deployed, cache versions are automatically updated using Jekyll’s site.time variable.

Manual Cache Bust

If you need to force a cache update:

# Update cache version
node scripts/update-cache-version.js

# Or deploy with cache busting
node scripts/deploy-with-cache-bust.js --commit

For Users Experiencing Cache Issues

Users will automatically see a notification when their cached version is outdated. They can:

  1. Click “Refresh Now” for immediate update
  2. Click “Later” to dismiss (will show again next visit)
  3. Wait 10 seconds for auto-dismiss

Technical Details

Cache Strategy

Note Storage Protection

CRITICAL: The cache busting system is designed to preserve all user data:

Protected localStorage Keys:

Only Removed Keys:

Safety Mechanisms:

  1. Explicit Protection List: All user data keys are explicitly protected
  2. Double-Check Validation: Keys are verified against protection list before removal
  3. Logging: All preserved keys are logged for verification
  4. Test Function: window.CacheBuster.testNoteStorageProtection() can verify protection works

Browser Compatibility

The cache busting system works across all modern browsers:

Performance Impact

Monitoring

Cache version information is included in:

Troubleshooting

If Users Still See Old Version

  1. Check if cache version is updating in health.json
  2. Verify _headers file is being applied
  3. Run manual cache bust script
  4. Check browser developer tools for 304 vs 200 responses

For Developers

  1. Always test cache busting after major updates
  2. Monitor health.json for cache version changes
  3. Use browser dev tools to verify version parameters
  4. Test in incognito/private mode to bypass cache
  5. Test note storage protection: Run window.CacheBuster.testNoteStorageProtection() in console

Testing Note Storage Protection

To verify that cache busting doesn’t affect note storage:

// Run in browser console
window.CacheBuster.testNoteStorageProtection()

This test will:

  1. Create sample note storage data
  2. Simulate cache clearing process
  3. Verify all note data is preserved
  4. Confirm only cache version is removed
  5. Clean up test data
  6. Return pass/fail results

Files Modified

Future Improvements