Four Ways a Static Site Breaks the Week You Leave GitHub Pages

Moving a static site off GitHub Pages is supposed to be the easy direction. The files are already static; you copy them to a server, point nginx at them, and change DNS. The build is identical. Nothing about the site changed.

Then four things broke, none of them in the build, and all of them within a week. Each one was a dependency the page host had been quietly providing, and each one failed in a way that looked like a completely different problem.

One: every URL with a Chinese character returned 404

The articles are bilingual, and the Chinese slugs are literal Chinese in the path:

/src/template/posts/工程化/html/三套缓存策略,让CDN不用再手动刷新.html 

On GitHub Pages those paths worked. On nginx they returned 404 while the file sat right there on disk, readable, correctly named.

The cause is request-line decoding. The browser sends percent-encoded bytes, and the server has to decide what those bytes mean before it maps them to a filename. Depending on the location block and how the path is passed to the filesystem, the decoded string does not have to match the UTF-8 filename you see in a shell listing.

The fix that worked was to stop hand-rolling the serving block and make the encoding explicit rather than implicit:

location / { try_files $uri $uri/ =404; } charset utf-8; 

The practical lesson is narrower than "configure nginx correctly": the page host and the operating system agreed on encoding, and your server may not. Test one non-ASCII URL immediately after cutover, not the homepage. The homepage will always be fine — it is ASCII by accident.

A second-order effect: .nojekyll files that existed only to stop a page host from running its own processor become meaningless. Leaving them in place is harmless but misleading, and the next person will assume something still reads them.

Two: ads.txt stopped being found, because of its name

ads.txt is a one-line file that tells ad networks who is allowed to sell your inventory. It has to be served at exactly /ads.txt.

On a case-insensitive filesystem — macOS by default, most Windows setups — a file named Ads.txt is the same file as ads.txt. It resolves either way. On the Linux server, Ads.txt and ads.txt are two different names, and the request for /ads.txt finds nothing.

This one is textbook, and it still happens, because the file was created once on a laptop years ago and nobody has typed its name since. For a day the ad units kept serving from cache, so the failure was invisible until a report showed the file could not be fetched.

The check worth adding to any deploy: assert that the exact filenames that must be byte-for-byte correct are lowercase where required — ads.txt, robots.txt, sitemap.xml, .nojekyll. A build step that lists them costs four lines and removes a class of failure that only appears in production.

Three: a fresh JSON file, a stale script, and broken images

This is the interesting one, because it is not a hosting difference at all — it is a cache policy that had been invisible while the site was small.

The setup: structured data lives in data.json files, and the client-side code that renders cards reads them. HTML and JSON are served with no-cache, so a deploy is visible immediately. The JavaScript bundles are served with a long cache and a content hash in the query string:

<script src="/components/feed/index.js?v=8f3a91c2"></script> 

The hash is the first eight characters of the file's SHA-1, rewritten at build time by a script that is idempotent — run it twice, no diff.

That works as long as the version bump actually runs. The week it did not, returning visitors got the previous script from cache against the new JSON. The new data had a different shape for image paths, and the old script concatenated a base prefix that no longer matched. Result: cards rendered, images 404, and only for visitors who had been to the site before. In a private browser window everything looked perfect.

The bug is the standard "cached script, uncached data" mismatch, and the reason it is worth writing down is the debugging path: the first instinct is to check the image files, which are fine; the second is to check the JSON, which is also fine. The mismatch only exists in the combination, and only for one class of visitor.

Two things made it stop recurring. First, resolve image URLs in exactly one place — a single helper that knows the base prefix — so there is no second implementation to fall out of sync. Second, make the version rewrite a step in the build chain rather than something remembered: if the build runs, the hash updates; if the hash updates, the browser fetches the new script.

Four: third-party images broke because of the Referer

The site embeds a few images from an external CDN. Those images worked for months and then began returning errors — not 404, but a rejection from the origin, on pages that the site owner could not reproduce from the command line.

The CDN was refusing requests that carried a Referer header from any origin it did not recognise. A plain curl sends no Referer, which is exactly why it looked fine.

The fix is one attribute, applied to images that are not yours:

<img src="https://cdn.example.net/shot.png" referrerpolicy="no-referrer" alt="Screenshot"> 

The general point: an image you do not host has a policy you do not control. Hotlink protection is common, and it fails silently in the browser's network tab with a status that looks like a permission decision rather than a missing file. Applying referrerpolicy="no-referrer" to external images is cheap insurance, and it also removes a small privacy leak.

What the week actually taught

Nothing here was a build problem, so nothing was caught by the build. The four failures were all "the environment changed underneath a working artifact":

  • path decoding, which the page host had handled
  • filename case, which a case-insensitive laptop had hidden
  • an asset-version step that was manual enough to skip
  • a third-party origin whose rules were never visible locally

The response that worked was to move each one from memory into a check: a post-deploy smoke test that loads one non-ASCII URL, one page with an external image, and one page as a returning visitor with a warm cache. Three URLs, two minutes, and it would have caught three of the four immediately.

The fourth — the version hash — is the one I would now treat as a build invariant rather than a habit. A cache key you have to remember to update is not a cache strategy; it is a countdown.

Originally published on wuhuajin.com.