Localizing GitHub Pages images with jsDelivr and static QA
Migrate hotlinked blog images to local assets with jsDelivr CDN, fix htmlproofer double-slash bugs, block AGENTS.md leaks, and upgrade Dev Containers.
External image hotlinks eventually break when third-party hosts change domains or enforce
Refererchecks. This post covers how I migrated every external image into my GitHub Pages repository with jsDelivr CDN, recovered from a double-slash orphan cleanup bug, blockedAGENTS.mdfrom leaking into_site/, and upgraded my Jekyll Dev Container to Debian Bookworm.
Tested with Jekyll 4.4, jekyll-theme-chirpy 7.6.0, html-proofer, and GitHub Actions (Ruby 3.4).
Why external hotlinks fail and how jsDelivr solves it
Long-running blogs accumulate image URLs pasted from older platforms—Velog, challenge sites, or GitHub issue attachments. Relying on third-party hotlinks creates fragile failure modes: a host can rotate its CDN domain, start returning 403 Forbidden on cross-site Referer headers, or serve uncached assets that drag down Largest Contentful Paint (LCP) and social preview cards.
| Approach | Pros | Trade-offs |
|---|---|---|
| Third-party hotlinks | Zero Git repository storage | Breaks silently on policy changes; no caching control |
Local assets/images/ + jsDelivr CDN | Lifecycle tied to the repo; global edge caching | Repo grows if uncompressed screenshots pile up (enforce a 1 MB cap) |
If your blog hosts hundreds of high-resolution photos or videos, object storage like Cloudflare R2 or S3 is a better fit than Git. For a technical blog with compressed diagrams and screenshots under 300 KB, storing images in assets/images/YYYY-MM-DD/ and serving them through jsDelivr keeps everything versioned in one place.
flowchart TD
MD["Markdown (/assets/images/...)"] --> DEV["Local preview (_config.yml)"]
MD --> PROD["CI build (_config_prod.yml)"]
PROD --> CDN["jsDelivr Multi-CDN prefix"]
PROD --> PROOF["htmlproofer integrity check"]
MD --> QA["qa_check.py static rules"]
Chirpy automatically prepends the cdn setting from _config.yml to any media path starting with /. I leave cdn: blank in _config.yml for local previews and set the jsDelivr endpoint only in _config_prod.yml:
1
2
3
4
# _config_prod.yml
# Used during GitHub Actions deploy:
# bundle exec jekyll b --config _config.yml,_config_prod.yml
cdn: 'https://cdn.jsdelivr.net/gh/cmsong111/blog@main'
That way, newly saved local images show up immediately under jekyll serve, while production builds on main automatically rewrite image URLs to jsDelivr. For details on cache headers and CDN behavior, see my earlier note on GitHub Pages image CDN caching.
The double-slash typo that broke orphan image cleanup
Right after localizing all external images, I ran a cleanup pass to delete unused (orphan) image files from assets/images/. Moments later, htmlproofer failed in CI, reporting a missing image in 2024-08-08-Wanted-be-challenge-8-api-Integration-test.md.
The root cause was a double-slash typo in the post Markdown—/assets followed by //images/2024-08-08/screenshot-1.png. Browsers silently normalize consecutive slashes, so the image had rendered fine for months. My naive string-matching cleanup script, however, looked for /assets/images/..., missed the double-slash reference, and deleted screenshot-1.png as an orphan.
htmlproofer caught the broken reference before deployment. I restored the file with git checkout, fixed the double slash in Markdown, and re-ran the check to green.
Figure 1. htmlproofer flagging the missing image from the double-slash typo and passing once the file was restored.
To stop this from happening again, I added three safeguards to .agents/skills/blog-writing/scripts/qa_check.py: double-slash path detection, third-party hotlink domain warnings, and an extra_refs collector that scans drafts, tabs, includes, data files, and _config.yml before flagging any image as unused.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# .agents/skills/blog-writing/scripts/qa_check.py (excerpt)
HOTLINK_DOMAINS = (
"velog.velcdn.com",
"static.wanted.co.kr",
"user-images.githubusercontent.com",
)
double_slash = "/assets/" + "/"
if double_slash in content:
errors["double_slash_assets_path"].append(p)
extra_refs = set()
for pat in ["_drafts/**/*.md", "_tabs/*.md", "_config.yml", "_includes/*.html", "_data/**/*"]:
for ef in glob.glob(pat, recursive=True):
if os.path.isfile(ef):
txt = open(ef, encoding="utf-8", errors="ignore").read()
for im in re.findall(r"assets/images/[^\s\"'\)]+", txt):
extra_refs.add(im.split("?")[0].split("#")[0])
Blocking AGENTS.md from leaking into _site/
During the same audit, I noticed an internal repository guidelines file (AGENTS.md) being published straight to the live site. I had previously renamed agent.md to AGENTS.md, but _config.yml still listed only the old filename under exclude. Any root Markdown file omitted from exclude gets copied straight into _site/ by Jekyll.
I added AGENTS.md to both _config.yml (exclude) and .github/workflows/pages-deploy.yml (paths-ignore), then added a config_missing_agents_exclude check in qa_check.py so a future config edit can’t accidentally drop it.
1
2
3
4
5
6
# _config.yml
exclude:
- README.md
- agent.md
- AGENTS.md
- writing-tone.md
Moving thin drafts out of _posts/ and upgrading Dev Containers to Bookworm
While auditing content quality for search indexing and AdSense, I found six unfinished stub posts—mostly one-line links or short reading notes—sitting in _posts/. I moved them to _drafts/ so Jekyll excludes them from production builds, and added a thin_content_under_600 rule in qa_check.py to block future thin stubs from slipping into _posts/.
Finally, I upgraded .devcontainer/devcontainer.json from the end-of-life Debian Bullseye base image to mcr.microsoft.com/devcontainers/jekyll:2-bookworm:
1
2
3
4
5
6
7
8
// .devcontainer/devcontainer.json
{
"name": "Jekyll",
"image": "mcr.microsoft.com/devcontainers/jekyll:2-bookworm",
"onCreateCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && sudo chown -R \"$(id -u):$(id -g)\" \"${GEM_HOME:-/usr/local/bundle}\"",
"forwardPorts": [4000, 35729],
"postCreateCommand": "bash .devcontainer/post-create.sh"
}
One Bookworm gotcha: /usr/local/bundle comes packaged with root ownership. Running chown inside onCreateCommand before postCreateCommand invokes bundle install prevents Bundler::PermissionError on fresh container builds.
Operational caveats and checklist
Warning: jsDelivr caches
@mainURLs on its edge network. Overwriting an existing image with the same filename can serve the stale version for hours. Append a version suffix (-v2.png) when replacing an image, or flush it via the jsDelivr Purge API.
Keep these operational practices in mind when maintaining a Jekyll repository:
- Cap individual images at 1 MB: Crop extra whitespace and compress PNG/WebP files so
git clonestays fast. - Run
htmlprooferwith--disable-externalin CI: Checking external URLs on every push causes flaky deploy failures from transient timeouts or403/429blocks. Keep CI focused on internal integrity and audit external links quarterly. - Split static QA and build verification: Use
qa_check.pyas a 1-second, Ruby-free first line of defense for Markdown and config rules, and letjekyll buildplushtmlproofervalidate Liquid rendering and final HTML links. - Guard internal repo docs in
_config.yml: Every root-level guide or script not meant for public visitors belongs inexclude.