Hacker News new | ask | show | jobs
by oefrha 687 days ago
GitHub Pages is pretty bad for static content with its universal

  Cache-Control: max-age=600
that can’t be changed. Your assets should have much longer expiry and hopefully be immutable. Just get a server, it’s cheap and you can do proper cache control and you’re not beholden to your Microsoft overlord.
3 comments

What does that matter?
With long expiry/immutable assets, only the HTML needs to be refetched from the server on refreshes or subsequent visits, instead of everything after merely ten minutes. On slow and/or high latency networks the difference can be huge. And you don’t even need to intentionally refresh — mobile browsers have been evicting background tabs since the dawn of time, and Chrome brought this behavior to desktop a while ago to save RAM (on by default).
But they are not refetched if etag is used properly: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ET...

Most you have is some HEAD requests.

By refetch I mean re-requested, which can return 304 responses. You still have to do a roundtrip for each resource in that case, and many websites (including static ones) have this waterfall of requests where html includes scripts and scripts include other scripts, especially now that some geniuses are pushing adoption of native esm imports instead of bundling. The roundtrips add up, and good luck if your link is unreliable in addition to being high latency. Compare that to proper caching where a refresh doesn’t request anything except maybe the html. I have experienced the web on such a link and it’s a shitshow.
Seems like a problem with the websites and not the cache expiry.

I have also experienced this, during dial up period, I agree its not pretty and most dont even consider it.

Ok. I don't think this is a big deal for the vast majority of blogs, like mine, that are hosted on GH pages. It's just HTML and some photos that are unique per post. But I also don't see why GH would put the number so low.
Because they have this one max-time for everything, from things that should be refetched frequently (html, unversioned scripts and stylesheets, etc.) to things that should be immutable (versioned scripts and stylesheets, images, etc.). They don’t understand your website. You do, and you can set exactly the right headers for the best user experience. Btw you can set the right headers with Netlify and Vercel as well.
Presumably so that when it shows the checkmark and says your website was updated you don't go there and wonder why it hasn't updated for you
I'm not confident a "cheap server" (like a $5/mo DO droplet) would be able to withstand being on the front page of HN, but I am pretty confident a GH pages page could withstand being on the front page of HN.
I had a blog article of mine on the HN front page a few years ago and the nginx serving static pages from an ultra cheap VPS didn't even break a sweat.
Is there a workaround to this within the realm of GitHub Pages? My initial search concludes: without GitHub allowing custom headers, no