66

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?

3

5 Answers 5

72

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

2
  • 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, 2018 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 Feb 13, 2022 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.

4
  • 6
    Well this approach is ok for html files. But I need my js file to have last modified header.
    – trante
    Aug 2, 2015 at 14:02
  • 8
    Till now (4/8/2015) still impossible.
    – tamyiuchau
    Aug 3, 2015 at 16:40
  • 2
    You might want to use Service Workers on your page as a workaround (either with manual caching inside of SW or by just modifying response headers).
    – RReverser
    Feb 25, 2016 at 11:57
  • 3
    and answer is: Don't use Github pages! Jan 30, 2017 at 12:20
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.

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.

1
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.