sveltekit-adapter-deno icon indicating copy to clipboard operation
sveltekit-adapter-deno copied to clipboard

Cache-Control on static files

Open pikanezi opened this issue 1 year ago • 2 comments

Hi,

Would it be possible to set a Cache-Control header for the static files? Also, do you know if it would work with Deno Deploy?

Thanks

pikanezi avatar Jun 28 '24 20:06 pikanezi

Yes this can work on Deno Deploy the example is doing so: https://sveltekit-adapter-deno.deno.dev/

Deno Deploy has a lot of weird support conditions so it just depends what packages and APIs you're using. From my experience it is slow and not a good hosting platform for websites.

Cache-Control headers are set for the immutable SvelteKit static files:

https://github.com/dbushell/sveltekit-adapter-deno/blob/12022ab2f38904e0044ca9341b523f831a97b6ad/files/mod.ts#L58-L61

For custom static files it would be too opinionated to add addtional headers.

I don't think other SvelteKit adapters provide an option. The node adapter suggestions making a custom server. You could do that for sveltekit-adapter-deno by copying build/mod.ts.

You could also proxy the server and at headers at a higher level. Cloudflare Workers would be one way to achieve this.

dbushell avatar Jun 29 '24 07:06 dbushell

Thanks for the quick answer. It seems svelte does not handle static caching at all so its an issue every adapter faces. I might do further research on this subject and try something of my own.

As for Deno Deploy, We're using it to host a static pre-rendered website and for this use case its fast enough so I wanted to improve its performance even more by providing caching.

Anyway, thank you again 😄

pikanezi avatar Jun 29 '24 10:06 pikanezi