Skip to content

Commit e310e01

Browse files
committed
Keep Cloudflare preview assets fresh across releases
1 parent 5a7d44b commit e310e01

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

DEPLOYMENT.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ submission drafts, internal notes, install endpoints, templates and the upstream
4545

4646
Preview-only transformations remove Omarchy's production Plausible script,
4747
add noindex meta/response headers, and set the homepage Open Graph URL to the
48-
preview domain. Source HTML retains upstream analytics/canonical metadata for
48+
preview domain. CSS/JavaScript entry URLs gain content-hash query versions;
49+
`Cache-Control: no-cache` requests revalidation of the remaining preview assets.
50+
This prevents old cached styles from being paired with new release markup.
51+
Source HTML retains upstream analytics/canonical metadata for
4952
review; do not upload the entire source tree to a different host.
5053

5154
Noindex is a request to search engines, **not access control**. This preview and

IMPLEMENTATION-NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ SHA-256 comparisons for all 33 referenced assets/imports/fonts. All five video
6464
links remained present. Missing/private paths returned 404. The public package
6565
removes production analytics and includes noindex headers.
6666

67+
The public release's browser check exposed a stale stylesheet in an existing
68+
Chrome session. Preview packaging now fingerprints CSS/JavaScript entry URLs
69+
and requests cache revalidation. The source tree keeps its original filenames
70+
and static architecture; no bundler or runtime cache workaround was added.
71+
6772
## Intentional deviations and limits
6873

6974
- The public preview uses Cloudflare Pages instead of upstream GitHub Pages.

bin/prepare-preview

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "fileutils"
44
require "tmpdir"
55
require "uri"
6+
require "digest"
67

78
root = File.expand_path("..", __dir__)
89
cache = File.join(root, ".cloudflare")
@@ -40,6 +41,15 @@ public_paths.each do |entry|
4041
html = html.gsub(/^[ \t]*<script\b[^>]*src=["']https:\/\/plausible\.io\/[^"']+["'][^>]*>\s*<\/script>\s*\n?/i, "")
4142
html = html.sub("</head>", " <meta name=\"robots\" content=\"noindex, nofollow\">\n </head>")
4243
html = html.sub('<meta property="og:url" content="https://omarchy.org/">', '<meta property="og:url" content="https://omarchy.rudyr.com/">') if relative == "index.html"
44+
# Fingerprint entry URLs so existing preview visitors cannot mix an old
45+
# cached stylesheet/script with new HTML. Source filenames stay unchanged.
46+
html = html.gsub(/((?:href|src)=["'])(\/assets\/[^"'?#]+\.(?:css|js))(["'])/) do
47+
opening, path, closing = Regexp.last_match.captures
48+
asset = File.join(root, path)
49+
abort "Missing linked entry asset: #{path}" unless File.file?(asset)
50+
version = Digest::SHA256.file(asset).hexdigest[0, 12]
51+
"#{opening}#{path}?v=#{version}#{closing}"
52+
end
4353
File.write(target, html)
4454
else
4555
FileUtils.cp(file, target)
@@ -50,6 +60,7 @@ end
5060

5161
File.write(File.join(output, "_headers"), <<~HEADERS)
5262
/*
63+
Cache-Control: no-cache
5364
X-Robots-Tag: noindex, nofollow
5465
X-Content-Type-Options: nosniff
5566
Referrer-Policy: strict-origin-when-cross-origin

0 commit comments

Comments
 (0)