deploy: drop the cache-warmer from sync-static.sh (no-op without CF proxy)
Cloudflare is DNS-only (grey-cloud) for upbeatbytes.com — no proxy/CDN/edge — so the warm() step (curl every chunk + key routes through the public domain) wasn't priming any edge; it just GET every asset from the already-fast static origin, generating thousands of internal-origin requests per deploy (the "traffic spike" in the logs). Removed it. Kept the valuable part: chunks-before-shell ordering, 14-day chunk grace, service-worker last. No change for visitors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+14
-35
@@ -1,51 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Sync the built static site to the live root in an order that avoids deploy-race
|
# Sync the built static site to the live root in an order that avoids deploy-race
|
||||||
# blank screens AND post-deploy slow loads. rsync isn't atomic, so a naïve
|
# blank screens. rsync isn't atomic, so a naïve `rsync --delete` can briefly serve
|
||||||
# `rsync --delete` can briefly serve a NEW index.html that points at chunks not
|
# a NEW index.html that points at chunks not synced yet (→ failed load), or delete
|
||||||
# synced yet (→ failed load), or delete old chunks an in-flight client still
|
# old chunks an in-flight client still needs. So the order is:
|
||||||
# needs. And even once synced, a new shell can point at chunks that aren't warm
|
# 1. new hashed chunks first, and DON'T prune old ones (14-day grace window)
|
||||||
# at the CDN edge yet, so the unlucky first visitor fetches them cold from the
|
# 2. other static assets (version.json, icons…), pruning removed files
|
||||||
# (residential) origin — the post-deploy slow-load window. So the order is:
|
# 3. the shell HTML — only once its chunks exist
|
||||||
# 1. new hashed chunks first, and DON'T prune old ones (grace window)
|
# 4. the service worker last — a returning client adopts it only after the rest
|
||||||
# 2. WARM those chunks at the edge BEFORE the shell goes live, so a new shell
|
# Old immutable chunks are pruned after the grace window to bound disk growth.
|
||||||
# never references cold chunks
|
#
|
||||||
# 3. other static assets (version.json, icons…), pruning removed files
|
# NOTE: there is intentionally NO edge cache-warming. Cloudflare is DNS-only
|
||||||
# 4. the shell HTML — only once its chunks exist AND are warm
|
# (grey-cloud) for upbeatbytes.com — no proxy/CDN/POP — so warming would just GET
|
||||||
# 5. the service worker last — a returning client adopts it only after the rest
|
# every asset from the residential origin (already µs-fast static): a no-op that
|
||||||
# 6. warm the shell + key routes after publish
|
# generated lots of internal request volume. Removed 2026-06-29.
|
||||||
# Old immutable chunks are pruned after a grace window to bound disk growth.
|
|
||||||
# NOTE: warming runs from this host, so it primes the Cloudflare POP nearest the
|
|
||||||
# origin (great for local/nearby users + our own post-deploy testing); a distant
|
|
||||||
# POP still cold-fills once on its first hit — inherent to a residential origin.
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
src="$1"; site="$2"
|
src="$1"; site="$2"
|
||||||
base="https://upbeatbytes.com"
|
|
||||||
|
|
||||||
# Warm a newline-separated list of paths (on stdin) through the public domain.
|
|
||||||
# Best-effort: a warm miss must never fail the deploy.
|
|
||||||
warm() { xargs -P 8 -I{} curl -fsS -o /dev/null --max-time 20 "$base{}" 2>/dev/null || true; }
|
|
||||||
|
|
||||||
# 1. New hashed chunks first (old ones kept — 14-day grace for in-flight clients).
|
# 1. New hashed chunks first (old ones kept — 14-day grace for in-flight clients).
|
||||||
rsync -a "$src/_app/immutable/" "$site/_app/immutable/"
|
rsync -a "$src/_app/immutable/" "$site/_app/immutable/"
|
||||||
|
|
||||||
# 2. Warm the chunks BEFORE publishing the shell, so the new shell never points
|
# 2. Other static assets (prune removed files), then 3. the shell, then 4. the SW.
|
||||||
# at chunks still cold at the edge (the post-deploy slow-load cause).
|
|
||||||
echo " warming new chunks (before publish)…"
|
|
||||||
find "$site/_app/immutable" -type f \( -name '*.js' -o -name '*.css' \) -printf '/_app/immutable/%P\n' | warm
|
|
||||||
|
|
||||||
# 3. Other static assets (prune removed files), then 4. the shell, then 5. the SW.
|
|
||||||
rsync -a --delete \
|
rsync -a --delete \
|
||||||
--exclude='_app/immutable/***' --exclude='index.html' --exclude='service-worker.js' \
|
--exclude='_app/immutable/***' --exclude='index.html' --exclude='service-worker.js' \
|
||||||
"$src/" "$site/"
|
"$src/" "$site/"
|
||||||
rsync -a "$src/index.html" "$site/index.html"
|
rsync -a "$src/index.html" "$site/index.html"
|
||||||
rsync -a "$src/service-worker.js" "$site/service-worker.js"
|
rsync -a "$src/service-worker.js" "$site/service-worker.js"
|
||||||
|
|
||||||
# 6. Warm the shell + key routes + remaining static now that they're published
|
|
||||||
# (primes CF↔origin even where no-cache; caches the cacheable shell/routes).
|
|
||||||
echo " warming shell + routes (after publish)…"
|
|
||||||
printf '%s\n' / /play /account /admin /service-worker.js /_app/version.json \
|
|
||||||
/manifest.webmanifest /words-5.json /words-6.json /logo.svg /favicon.svg \
|
|
||||||
/icon-192.png /icon-512.png /fonts/inter-latin-wght-normal.woff2 | warm
|
|
||||||
|
|
||||||
# Bound disk growth: prune immutable chunks older than the grace window.
|
# Bound disk growth: prune immutable chunks older than the grace window.
|
||||||
find "$site/_app/immutable" -type f -mtime +14 -delete 2>/dev/null || true
|
find "$site/_app/immutable" -type f -mtime +14 -delete 2>/dev/null || true
|
||||||
|
|||||||
Reference in New Issue
Block a user