← Back to all products
$19
Page Speed Optimizer
Page speed analysis and optimization with Core Web Vitals checks and actionable recommendations.
PythonMarkdown
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 9 files
page-speed-optimizer/
├── LICENSE
├── README.md
├── examples/
│ └── sample.html
├── free-sample.zip
├── guide/
│ ├── 01_features.md
│ ├── 02_cli-reference.md
│ └── 03_examples.md
├── index.html
└── src/
└── page_speed_optimizer.py
📖 Documentation Preview README excerpt
Page Speed Optimizer
Part of the Landing Lab by CodeVault
Analyze and optimize your landing page files: minify HTML, CSS, and JavaScript; add lazy loading to images; audit asset sizes; and generate a performance score with actionable recommendations. Actually fixes problems, not just reports them.
Features
- HTML minification (comments, whitespace, collapse)
- CSS minification (comments, whitespace, selectors, semicolons)
- JavaScript minification (comments, whitespace, string-safe)
- Automatic lazy loading injection (skips hero image)
- Full directory audit with performance scoring (0-100)
- Per-file size checks against best-practice thresholds
- Image format recommendations (WebP/AVIF conversion)
- Inline CSS/JS detection and extraction advice
- Device breakdown by file type with size percentages
- Text and JSON report output
- Python stdlib only — zero pip dependencies
Quick Start
# Analyze a single HTML file
python src/page_speed_optimizer.py --analyze examples/sample.html
# Minify HTML
python src/page_speed_optimizer.py --minify examples/sample.html --output index.min.html
# Minify CSS
python src/page_speed_optimizer.py --minify-css style.css --output style.min.css
# Add lazy loading to images
python src/page_speed_optimizer.py --lazy-load index.html --output index.lazy.html
# Audit an entire directory
python src/page_speed_optimizer.py --audit-dir ./dist/ --report
CLI Reference
| Flag | Description |
|---|---|
--analyze | Analyze a single HTML file |
--minify | Minify an HTML file |
--minify-css | Minify a CSS file |
--minify-js | Minify a JS file |
--lazy-load | Add lazy loading to an HTML file |
--audit-dir | Audit all assets in a directory |
--report | Generate audit report |
--output, -o | Output file |
--format, -f | Output format: text or json |
--verbose, -v | Enable verbose logging |
Configuration
See examples/sample.html for a sample landing page to test with.
Examples
... continues with setup instructions, usage examples, and more.
📄 Code Sample .py preview
src/page_speed_optimizer.py
#!/usr/bin/env python3
"""
Page Speed Optimizer — Landing Lab by DataNest
Analyze and optimize your landing page files: minify HTML, CSS, and
JavaScript; detect lazy-loading opportunities for images; audit asset
sizes; and generate a performance score with actionable recommendations.
Why this exists:
Every 100ms of load time costs you 1% of conversions (Amazon's data).
But most performance tools just give you a score — they don't fix
anything. This tool actually minifies your files, adds lazy loading
attributes, and tells you exactly what to fix next.
Usage:
python page_speed_optimizer.py --analyze index.html
python page_speed_optimizer.py --minify index.html --output index.min.html
python page_speed_optimizer.py --minify-css style.css --output style.min.css
python page_speed_optimizer.py --audit-dir ./dist/ --report
License: MIT
"""
from __future__ import annotations
import argparse
import json
import logging
import os
import re
import sys
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
LOG = logging.getLogger("page-speed-optimizer")
# File size thresholds (bytes)
MAX_HTML_SIZE = 100_000 # 100KB — HTML should be lean
MAX_CSS_SIZE = 50_000 # 50KB for a single CSS file
MAX_JS_SIZE = 100_000 # 100KB for a single JS file
MAX_IMAGE_SIZE = 200_000 # 200KB per image
MAX_TOTAL_PAGE_SIZE = 1_500_000 # 1.5MB total page weight target
# Image formats that support lazy loading
LAZY_LOAD_TAGS = {"img", "iframe"}
# ... 578 more lines ...