Github pages, HTTP headers
Asked Answered
A

5

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?

Archetype answered 10/2, 2013 at 14:10 Comment(4)
#12557093 #3956955Archetype
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 pagesDeipnosophist
You can use 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://mcmap.net/q/297590/-is-there-any-way-to-use-sharedarraybuffer-on-github-pages and stefnotch.github.io/web/COOP%20and%20COEP%20Service%20Worker and dev.to/stefnotch/…Lynea
Also linking to that question: webapps.stackexchange.com/questions/119286/…Sputter
A
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.

Archetype answered 27/2, 2013 at 20:57 Comment(2)
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.Lipophilic
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 itJumble
H
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.

Hinze answered 2/8, 2015 at 12:10 Comment(4)
Well this approach is ok for html files. But I need my js file to have last modified header.Archetype
Till now (4/8/2015) still impossible.Hinze
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).Centri
and answer is: Don't use Github pages!Allowable
R
9

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.

Roundy answered 25/9, 2018 at 12:44 Comment(0)
P
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.

Pretentious answered 22/11, 2018 at 3:26 Comment(1)
Comparative Breakdown of GitHub Pages vs. Netlify - www.netlify.com/github-pages-vs-netlifyPentagrid
K
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

Koester answered 29/6, 2022 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.