dbushell / sveltekit-adapter-deno

🦕 SvelteKit Adapter for Deno and Deno Deploy
MIT License
49 stars 1 forks source link

Cache-Control on static files #9

Open pikanezi opened 2 months ago

pikanezi commented 2 months ago

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

dbushell commented 2 months ago

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.

pikanezi commented 2 months ago

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 😄