Optimize MkDocs Performance¶
Learn how to improve build times, reduce page load speeds, and optimize your MkDocs Material site performance.
Build Speed Optimization¶
Disable Strict Mode During Development¶
Speed up development builds by temporarily disabling strict mode:
Production Builds
Always re-enable strict mode for production to catch broken links and invalid references.
Use Dirty Reload for Faster Previews¶
Get instant updates during development with dirty reload:
Dirty Reload Behavior
Dirty reload only rebuilds changed files, dramatically reducing preview refresh time during active editing.
Image Optimization¶
Convert to WebP Format¶
WebP provides superior compression compared to PNG or JPEG:
# Convert PNG to WebP
cwebp -q 80 image.png -o image.webp
# Convert JPEG to WebP
cwebp -q 80 image.jpg -o image.webp
Quality Settings
-q 80: Good balance between quality and file size-q 90: Higher quality, larger file-q 70: More compression, lower quality
Enable Lazy Loading¶
Defer off-screen image loading to improve initial page load:
{ loading=lazy }
{ loading=lazy width="600" }
Best Practice
Apply lazy loading to all images below the fold (not visible on initial page load).
Search Performance¶
Configure Search Plugin¶
Optimize search indexing and performance:
plugins:
- search:
separator: '[\s\-,:!=\[\]()"`/]+|\.(?!\d)|&[lg]t;|(?!\b)(?=[A-Z][a-z])'
lang:
- en
- fr
Search Configuration
separator: Regex pattern for word boundary detectionlang: Languages for search stemming and tokenization
Performance Monitoring¶
Measure Build Time¶
Track build performance over time:
# Time the build process
time uv run mkdocs build
# Verbose output for debugging
uv run mkdocs build --verbose
Analyze Site Size¶
Monitor generated site size:
Performance Target
Aim for build times under 10 seconds and total site size under 50MB for optimal performance.