server static file + caching
Hey guys,
I am serving a static folder called public and it's all working well, I can access my files, eg styles.css. Here is the code for it:
However I didn't realize that hono wasn't caching the assets in
/public
by default. Is there any way to tell hono to cache that directory ?12 Replies
This does depends on the deployment solution you are using. Most of them automatically caches these assets for you
like cloudflare, vercel
Sorry I should have mentioned that in the question, I was talking about the built in browser cache.
I think browser already does it for the client, except if you have enabled
disabled cache
in your network tab (usually for testing)that's why I am a bit confused as well as the browser isn't caching it. I don't have
disabled cache
enabled. Caching does work as it can cache other assets. But not the one from /public/*
.Someone told me about this message, is this helpful in your case? - https://discord.com/channels/1011308539819597844/1012485912409690122/1265753791274156233
not really as I am not using cloudflare. I am just running a basic vps
what is your setup looks like and why is JS getting cached and not your HTML and CSS. Can you share a reproduction of this? I will try to figure this out tomorrow
Thanks for taking your time and looking into it 🙏 here is the github repo: https://github.com/AugustinSorel/ungrading-portfolio
GitHub
GitHub - AugustinSorel/ungrading-portfolio
Contribute to AugustinSorel/ungrading-portfolio development by creating an account on GitHub.
Can you point me to the files were you are serving those files
My bad I should have explained that, sorry. if you run
bun styles:build
this should generate the css file in public/styles.css
. Then in my /src/index.ts
I am serving the folder public
statically.
if you then run the app with bun dev
or bun server:dev
and open up the dev tool you should see that the css file isn't being cached by the browser.Okay. Also, check out this issue https://discord.com/channels/1011308539819597844/1011308539819597847/1281919444775342162 which is adding headers to the static files, maybe once this is merged your problem will be resolved!
that sounds good I will keep an eye on it. Thanks for the help 🫶