This guide explains how to deploy the cache-busting solution for the Buzzwald widget.
The cache-busting solution ensures users always get the latest widget version without changing their embed code. It works by:
- Loader Script: A lightweight script that never changes and can be cached
- Version Check: Fetches current version info from
version.json - Dynamic Loading: Loads the actual widget with cache-busting parameters
Users will now use this single script tag that never changes:
<script>
window.BuzzwaldConfig = {
id: 'your-assistant-id',
token: '', // Optional - will be fetched automatically
backgroundColor: '#FFFF00',
iconColor: '#000000'
};
</script>
<script src="https://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/buzzwald.js"></script>After running bun run build, these files are created in dist/:
buzzwald.js- The cache-busting loader (users embed this)buzzwald-widget.js- The actual widget codeversion.json- Version information for cache busting
The version.json file contains:
{
"version": "0.0.1",
"commit": "abc1234",
"timestamp": 1703123456789,
"buildDate": "2023-12-21T10:30:45.123Z",
"buildId": "0.0.1-abc1234-1703123456789",
"cacheBuster": "v=0.0.1&t=1703123456789"
}bun run build:releaseThis creates the dist/ directory with all necessary files.
- Go to your GitHub repository
- Click "Releases" → "Create a new release"
- Choose a tag version (e.g.,
v0.0.2) - Upload the
dist/folder contents as release assets, OR - Let GitHub Actions build and attach the assets automatically
JSDelivr automatically updates @latest when you create a new GitHub release:
https://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/buzzwald.jshttps://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/buzzwald-widget.jshttps://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/version.json
- Users embed this script (it never changes)
- Can be cached indefinitely by browsers
- Responsible for loading the actual widget
- Loader fetches
version.jsonwith cache-busting headers - Cached locally for 5 minutes to avoid excessive requests
- Contains timestamp and version info
- Widget is loaded with URL parameters:
?v=0.0.1&t=1703123456789 - Browser treats this as a new URL when version/timestamp changes
- Bypasses browser cache when you deploy updates
- If version check fails, loads widget with current timestamp
- Ensures widget always loads even if version service is down
- Graceful degradation for network issues
- Duration: 5 minutes
- Purpose: Avoid excessive version checks
- Storage: localStorage
- Duration: 1 hour
- Purpose: Avoid re-downloading same widget version
- Storage: localStorage
bun run test:cache-bustingOpens the cache-busting test page with tools to:
- Simulate version updates
- Clear cache
- Monitor network requests
- Check version info
After deployment, test with:
- Load widget on test page
- Clear browser cache
- Reload page - should get latest version
- Check network tab for cache-busting parameters
- Check browser console for errors
- Verify version.json is accessible
- Check network tab for failed requests
- Test with cache disabled
- Confirm GitHub release was created
- Check JSDelivr cache (may take 1-2 minutes)
- Verify version.json has updated timestamp
- Test with different browser/incognito
- Monitor version check frequency
- Check localStorage usage
- Optimize version.json size if needed
- Consider CDN performance
<script src="https://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/buzzwald-widget.js"></script><script src="https://cdn.jsdelivr.net/gh/StructuredLabs/buzzwald-client@latest/dist/buzzwald.js"></script>- Update documentation with new embed code
- Send notification to existing users
- Keep old method working for backward compatibility
- Monitor usage analytics
- Eventually deprecate old method
- Version check success rate
- Widget load time
- Cache hit/miss ratios
- Error rates by browser
- User update lag time
Consider adding analytics to track:
- Loader script loads
- Version check requests
- Widget load success/failure
- Cache effectiveness
- Version.json contains no sensitive information
- Uses HTTPS for all requests
- No user data in version checks
The loader script:
- Doesn't use
eval()or inline scripts - Fetches resources from same origin (JSDelivr)
- Compatible with strict CSP policies
- Delta Updates: Only load changed parts of widget
- Progressive Loading: Load core features first, then enhancements
- A/B Testing: Load different widget versions for testing
- Rollback Capability: Quickly revert to previous version
- Regional CDN: Use geo-specific CDN endpoints