Guide · Web performance
GitHub Pages cache: why your update doesn't show
You deployed, the workflow is green, and the site still looks old. On GitHub Pages the usual cause is a 10-minute browser cache you can't configure. Here's how to confirm it, and a small script that stops it from breaking your CSS and JavaScript.
The short answer
- Just need to see your change? Hard-reload: Cmd+Shift+R on macOS, Ctrl+Shift+R on Windows and Linux.
- Why it happens: GitHub Pages sends
Cache-Control: max-age=600, so a browser may reuse a file for 10 minutes without asking. - You can't change that header in your repository.
- Lasting fix for CSS and JavaScript: change their URL whenever their content changes.
Is it the deploy or the cache?
Two delays look the same. GitHub says changes can take up to 10 minutes to publish, and only then does the browser cache matter. Find out which one you have:
# what is live right now?
curl -sI https://example.com/styles.css
# does the live file contain your change?
curl -s https://example.com/styles.css | grep "new-class"| What you see | Where the problem is |
|---|---|
| The change isn't in the live file | Not deployed yet. Check the Actions tab. |
| The live file is right, the browser is wrong | Browser cache |
| It works in a private window | Browser cache |
last-modified is older than your deploy | The deploy or the CDN |
What GitHub Pages really sends
These are response headers from this site, which runs on GitHub Pages, in November 2026:
cache-control: max-age=600
last-modified: Tue, 24 Nov 2026 17:23:20 GMT
etag: "6b05c808-7d58"
x-cache: HIT- Everything gets 10 minutes. HTML, CSS and images all had the same
max-age=600. - The ETag is deploy time plus file size. Here
6b05c808is the timestamp in hexadecimal and7d58is 32,088 bytes. - So every deploy makes unchanged files look new. An image committed two days earlier had that day's deploy as its
last-modifieddate, so browsers have to download it again. - Between deploys, revalidation is cheap. Sending the ETag back returned a small
304 Not Modified.
The worst case: new HTML with old CSS
Each file's 10 minutes starts when the browser downloads it. A visitor who loaded styles.css just before your deploy, then opens a page they haven't visited yet, gets new HTML with the old stylesheet. New elements appear unstyled, or a new button doesn't work because its script is missing.
It's hard to notice yourself, because it depends on when each file was cached. If a feature works for some visitors and not others right after a deploy, suspect this first.
The fix: version your CSS and JavaScript
If the URL changes whenever the content changes, the browser has no old copy to reuse. This script hashes each file and updates the links in every HTML page. It needs no dependencies, only Node.js 20 or newer:
import { createHash } from "node:crypto";
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
const ASSETS = ["/styles.css", "/app.js"];
const versions = ASSETS.map((path) => {
const hash = createHash("sha256").update(readFileSync("." + path)).digest("hex").slice(0, 8);
// matches href="/styles.css" and an older href="/styles.css?v=1a2b3c4d"
const pattern = new RegExp(`((?:href|src)=")${path.replace(/\./g, "\\.")}(?:\\?v=[a-f0-9]+)?(")`, "g");
return { pattern, url: `${path}?v=${hash}` };
});
const pages = readdirSync(".", { recursive: true })
.filter((file) => file.endsWith(".html") && !file.includes("node_modules"));
for (const page of pages) {
const before = readFileSync(page, "utf8");
const after = versions.reduce(
(html, { pattern, url }) => html.replace(pattern, (_, start, end) => start + url + end),
before,
);
if (after !== before) {
writeFileSync(page, after);
console.log("updated", page);
}
}<link rel="stylesheet" href="/styles.css?v=d68d3463">
<script src="/app.js?v=4d61a7b4"></script>Run node version-assets.mjs before you commit. If nothing changed, it does nothing, so your Git history stays clean.
Or run it on every deploy
In the repository settings, set the Pages source to GitHub Actions. The links are then updated during the deploy, and your committed HTML stays untouched:
name: Deploy
on:
push:
branches: [main] # or master
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v6
- run: node version-assets.mjs
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v4
with:
path: .
- id: deployment
uses: actions/deploy-pages@v4With path: . the whole repository is published, so keep private files out of it or upload a build folder instead.
Query string or hashed filename?
styles.css?v=d68d3463 | styles.d68d3463.css | |
|---|---|---|
| Setup | Simple, no new files | Needs a build step |
| Skips the browser cache | Yes | Yes |
| Skips the GitHub CDN cache | Not in my test | Yes |
| Old pages still work | Yes | Only if you keep old files |
In my test, the CDN ignored the query string: random, never-used values all came back as x-cache: HIT. The query string still solves the browser problem, which is the common one. Choose hashed filenames if you need each URL to always return exactly one version, and keep the previous files for a while, because a cached page may still ask for them.
What doesn't work
<meta http-equiv="Cache-Control">: don't rely on it. It can't set caching for your CSS, JavaScript or images.- A
_headersfile: that's a Netlify and Cloudflare Pages feature. GitHub Pages doesn't apply it. - A random version on every page load: it works, but disables caching completely and makes every visit slower.
- Deploying again: it doesn't clear copies already in your visitors' browsers.
If you need full control over headers, put a CDN such as Cloudflare in front of the site, or use a host that lets you configure them. For a small site, versioned URLs are usually enough.
FAQ
How long does GitHub Pages cache files?
10 minutes. In November 2026, GitHub Pages sent Cache-Control: max-age=600 for HTML, CSS and images. After that the browser checks whether the file has changed.
How do I clear the GitHub Pages cache?
You can't clear your visitors' browsers. For yourself, use a hard reload: Cmd+Shift+R on macOS or Ctrl+Shift+R on Windows and Linux. For everyone else, change the URL of your CSS and JavaScript files when their content changes.
Can I set Cache-Control headers on GitHub Pages?
No. GitHub Pages doesn't let you configure response headers. Use versioned file URLs, put a CDN in front of the site, or choose a host with configurable headers.
Why is my CSS not updating on GitHub Pages?
Either the deploy hasn't finished or your browser is using a cached copy. Fetch the file with curl. If the live file has your change, it's the browser cache and a hard reload will fix it.
Does cache busting help with the HTML page itself?
No. People need the page's normal URL, so it can stay cached for up to 10 minutes. Versioning makes sure that once they get the new HTML, they also get the matching CSS and JavaScript.