67

I serve some of my files from my Github pages account. But when I check my "js" files' headers, I saw following:

Last-Modified:Sun, 10 Feb 2013 14:00:46 GMT 
Expires:Sun, 10 Feb 2013 14:13:23 GMT
Cache-Control:max-age=600

This file was commited 14 days ago. But I don't plan these files so frequent. So I need to make much bigger max-age value and change Last-Modified value to last commited date.

Is it possible to change headers of Github pages?

Samyak Bhuta
  • 1,256
  • 7
  • 20
trante
  • 33,518
  • 47
  • 192
  • 272
  • http://stackoverflow.com/questions/12556593/determining-a-page-is-outdated-on-github-pages http://stackoverflow.com/questions/3956455/html-5-cache-manifest-vs-etags-expires-or-cache-control-header/ – trante Feb 17 '13 at 18:22
  • 1
    It is possible to use service workers to set quite a few headers. With service workers, you can handle the entire caching yourself. You can even [set the COOP/COEP headers and get `SharedArrayBuffer` to work on GitHub pages](https://stackoverflow.com/a/68675301/3492994) – Stefnotch Aug 06 '21 at 09:24
  • You can use https://github.com/gzuidhof/coi-serviceworker to add HTTP headers to any GH pages site. It’s a service worker that uses the techniques described in https://stackoverflow.com/a/68675301/3492994 and http://stefnotch.github.io/web/COOP%20and%20COEP%20Service%20Worker/ and https://dev.to/stefnotch/enabling-coop-coep-without-touching-the-server-2d3n – sideshowbarker Jun 16 '22 at 12:49
  • Also linking to that question: https://webapps.stackexchange.com/questions/119286/caching-assets-in-website-served-from-github-pages – Spenhouet Aug 20 '23 at 11:56

5 Answers5

74

I asked this to Github admins, and they told me that "it is not possible" to change headers. They added this issue to wishlist.

trante
  • 33,518
  • 47
  • 192
  • 272
  • 1
    Still not possible. Github doesn't want to add possibility to modify Github Pages HTTP headers. The current only workaround is to use HTML `meta` tags. – Binyamin Mar 13 '18 at 18:27
  • Can we vote on the items in this wishlist? Or any recommended way to request this feature? Maybe if enough people will ask, they just consider it – Momin Bin Shahid Feb 13 '22 at 16:15
22

The answer is no, however we can stimulate html header on html pages using <meta http-equiv> tag.

<meta http-equiv="last-modified" content="Sun, 10 Feb 2013 14:00:46 GMT " />
<meta http-equiv="cache-control" content="Private" />
<meta http-equiv="Expires" content="600" />

You can embed these snippets into the HTML page.

Richie Bendall
  • 7,738
  • 4
  • 38
  • 58
tamyiuchau
  • 329
  • 2
  • 5
8

This is for all the people still having this problem and coming here from google.

Had the same problem recently. Actually it is possible if you are stubborn enough and wish to use some extra, third party services. What you need to do, is to use free tier heroku app with custom nginx buildpack. This buildpack would work as a proxy pass, which can add/remove HTTP headers as you please.

You will lose GitHub CDN though, so it may be good idea to leverage another service - cloudflare to do just that (and SSL as a bonus).

I wrote an article with detailed setup how to do this, if somebody is intereseted: https://www.rzegocki.pl/blog/custom-http-headers-with-github-pages/ - the setup is pretty cumbersome but it works.

Ajgon
  • 111
  • 1
  • 5
5

It's currently not possible in Github Pages. You can use Github with Netlify. They let you change headers. They also have nice features like forms, prerendering and more. Which all are missing in Github Pages.

Howdy
  • 557
  • 7
  • 12
  • 2
    Comparative Breakdown of GitHub Pages vs. Netlify - [www.netlify.com/github-pages-vs-netlify](https://www.netlify.com/github-pages-vs-netlify/) – Alex Klaus May 24 '19 at 05:43
0

Cloudflare can fix that issue and have better automation in network areas - can only be DNS provider. Don't enable HTTPS on github.io page for compatibility (it provide automatically by CF).

Cloudflare Pages Netlify can generate with _headers file - they aren't free or cheap if site is bigger. Provide externall upload to automate build on your machine so only serving is what we see in this problem (https://docs.netlify.com/routing/headers/#syntax-for-the-headers-file).

Service Work - won't show up for pagespeed and other metric

Meta Tags - won't work for other files like static js and css

On the discussion (give thumb up) - https://github.com/github-community/community/discussions/11884 They can add option as they use varnish

Patryk
  • 329
  • 3
  • 12