Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No caching on statiq.dev #63

Open
ociaw opened this issue Dec 30, 2022 · 2 comments
Open

No caching on statiq.dev #63

ociaw opened this issue Dec 30, 2022 · 2 comments
Labels
Discussion/Question Discussions or questions about the code Feedback Needed Further information is requested

Comments

@ociaw
Copy link

ociaw commented Dec 30, 2022

I noticed that none of the assets or mirrors are cached on statiq.dev, so big things like mermaid.js are being downloaded on every single request, which can take a while on slower connections (crappy cellular/satellite). These are all the uncached requests when hitting the home page a second time:

Screenshot of a Firefox network log. The requests are sorted by transfer size, with the the largest being mermaid.min.js with 329 kilobytes transfered.

It looks like the cache-control header for the whole site is public, max-age=0, must-revalidate - I'd suggest caching everything for at least a couple hours by default, and stuff under /mirror for a fairly long time (months?), since those libraries are inherently versioned.

@daveaglick
Copy link
Member

Interesting find - the site is hosted on Netlify so these are their default headers (I don't edit them, at least not right now).

I found this article on the Netlify site about the cache-control header they use: https://www.netlify.com/blog/2017/02/23/better-living-through-caching/

It looks like they're relying on the etag and conditional caching to provide rapid cache invalidation when (and only when) the content changes:

"etag" = a version hash, which we send with all content, that the browser provides BACK to our servers when it tries to re-fetch one of these resources (as you saw above — we’ll always set assets to require re-fetching). A browser tries a conditional get in this situation, providing the etag with the initial request to let our server confirm that this version is still current if the etag we would serve with the new content matches, our server returns an HTTP 304 which allows the browser to use its cached content instead of the client having to re-download the content.

So what's especially interesting here is that your browser doesn't seem to be honoring the intent of this caching behavior - I.e. you're requesting the mermaid.min.js file over and over, even though the previous one fetched should have the same etag.

In my own browser I can see the etag header being sent:
image

Is it possible yours is actually just transfering the headers and not the whole file too? I see the amount transferred in your screen shot is much lower than the actual size of the content (which I assume means the browser cache is filling in the file content itself).

@daveaglick daveaglick added Feedback Needed Further information is requested Discussion/Question Discussions or questions about the code labels Feb 3, 2023
@ociaw
Copy link
Author

ociaw commented Feb 4, 2023

It's definitely not just headers - I think the difference between transferred and actual size is due to compression. I see that Firefox is sending a new/unique etag for each request, so it doesn't seem to care to cache it at all.

Interestingly, I just tried it on a clean Firefox profile and it seems to cache everything as expected, and the etag works correctly. I'm guessing it's something to do with my extensions or settings? I'll play around with it more and see if I can narrow down the cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion/Question Discussions or questions about the code Feedback Needed Further information is requested
Development

No branches or pull requests

2 participants