Close residual perf gaps: LCP WebP srcset, lazy route chunks, motion split.
Crop and compress hero outreach-01 to responsive WebP/JPEG variants, serve via picture element with preload; lazy-load Home, Donate, and Assistance routes; isolate framer-motion in its own Vite chunk. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate responsive WebP/JPEG variants for hero LCP and community gallery.
|
||||
# Requires: ImageMagick (convert). Run from repo root: ./scripts/optimize-community-photos.sh
|
||||
|
||||
set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
MIM_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
SRC_DIR="$MIM_ROOT/public/photos/community"
|
||||
OUT_DIR="$SRC_DIR/optimized"
|
||||
|
||||
if ! command -v convert >/dev/null 2>&1; then
|
||||
echo "Error: ImageMagick convert is required." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
# Hero LCP: outreach-01 — crop to 16:10 (display aspect), then resize widths
|
||||
HERO_SRC="$SRC_DIR/outreach-01.jpg"
|
||||
if [[ ! -f "$HERO_SRC" ]]; then
|
||||
echo "Missing $HERO_SRC" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HERO_CROP="$OUT_DIR/outreach-01-crop.jpg"
|
||||
convert "$HERO_SRC" -auto-orient -gravity center -crop 1200x750+0+0 +repage \
|
||||
-strip -interlace Plane -quality 82 "$HERO_CROP"
|
||||
|
||||
for w in 480 720 960 1200; do
|
||||
h=$((w * 10 / 16))
|
||||
base="$OUT_DIR/outreach-01-${w}"
|
||||
convert "$HERO_CROP" -resize "${w}x${h}^" -gravity center -extent "${w}x${h}" \
|
||||
-strip -interlace Plane -quality 82 "${base}.jpg"
|
||||
convert "$HERO_CROP" -resize "${w}x${h}^" -gravity center -extent "${w}x${h}" \
|
||||
-strip -quality 82 "${base}.webp"
|
||||
done
|
||||
|
||||
# Gallery tiles (2–5): 600w max for grid
|
||||
for n in 02 03 04 05; do
|
||||
src="$SRC_DIR/outreach-${n}.jpg"
|
||||
[[ -f "$src" ]] || continue
|
||||
for w in 400 600; do
|
||||
base="$OUT_DIR/outreach-${n}-${w}"
|
||||
convert "$src" -auto-orient -resize "${w}x" -strip -interlace Plane -quality 82 "${base}.jpg"
|
||||
convert "$src" -auto-orient -resize "${w}x" -strip -quality 82 "${base}.webp"
|
||||
done
|
||||
done
|
||||
|
||||
echo "Optimized assets in $OUT_DIR"
|
||||
ls -lah "$OUT_DIR"
|
||||
Reference in New Issue
Block a user