Asset Versioning for Jekyll Website
This document explains the asset versioning system implemented to prevent browser caching issues and ensure users always see the latest version of your website.
Overview
The asset versioning system automatically appends version parameters to static assets (CSS, JavaScript, images, etc.) based on their content hash. This ensures that when you update any asset, browsers will fetch the new version instead of using cached content.
How It Works
1. Automatic Versioning
- Content-based hashing: Uses MD5 hash of file content to generate unique version parameters
- Jekyll integration: Leverages Jekyll’s built-in
asset_urlfilter for reliable versioning - Zero maintenance: No manual version number management required
2. Configuration
The system is controlled by settings in _config.yml:
# Asset versioning configuration
asset_versioning: true
asset_cache_bust: true
3. Implementation
Assets are referenced using Liquid filters instead of direct paths:
Before (hardcoded paths):
<link rel="stylesheet" href="/assets/css/style.css">
<script src="/assets/js/main.js"></script>
After (versioned paths):
<link rel="stylesheet" href="/assets/css/style.css">
<script src="/assets/js/main.js"></script>
Available Filters
Primary Filter
asset_hash_versioned- Main filter for all asset types (recommended)- Uses content-based MD5 hash for reliable cache busting
- Only changes when file content actually changes
- Provides 8-character hash for clean URLs
Alternative Filters
asset_versioned- Uses timestamp-based versioning- Updates on every build regardless of content changes
- Useful for development/testing scenarios
Files Updated
The following files have been updated to use asset versioning:
Templates
_includes/head.html- CSS and favicon references_layouts/default.html- JavaScript references_includes/navigation.html- Resume PDF and search icon_includes/footer.html- Social media iconsindex.md- Home page specific assets
Configuration
_config.yml- Added versioning configuration_plugins/asset_versioning.rb- Custom Liquid filters
Benefits
- Automatic Cache Busting: No manual intervention needed
- Content-Based: Only changes when file content actually changes
- Performance: Long-term caching for unchanged assets
- Reliability: Uses Jekyll’s proven asset handling
- Maintainability: Single configuration controls entire system
Example Output
When enabled, asset URLs will look like:
/assets/css/style.css?v=db730cc6c
/assets/js/main.js?v=244a5d650
/assets/images/logo.png?v=45609868e
The version parameters are content-based MD5 hashes that only change when the file content changes.
Disabling Versioning
To disable asset versioning, set in _config.yml:
asset_versioning: false
asset_cache_bust: false
Testing
To verify versioning is working:
- Build the site:
jekyll build - Check output: Look for versioned URLs in
_site/files - Browser testing: Use developer tools to verify new assets are fetched
- Content changes: Modify an asset and rebuild to see version change
Troubleshooting
Common Issues
- Assets not loading: Check that paths start with
/in filter calls - Version not updating: Ensure
asset_versioning: truein config - Build errors: Verify all asset files exist at specified paths
Debug Mode
Add to _config.yml for debugging:
asset_versioning: true
asset_cache_bust: true
debug: true
Best Practices
- Use
asset_url_versionedfor most cases - Test after changes to ensure versioning works
- Keep assets organized in logical directory structure
- Monitor build times as versioning adds processing overhead
- Use CDN-friendly versioning for production deployments
Future Enhancements
Potential improvements:
- CDN integration
- Service worker cache management
- Asset bundling and minification
- Progressive loading strategies