-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[feat] Add configurable cache to worker responses #1771
Conversation
|
I'd like to point out a couple things regarding the current implementation of detecting static asset requests. My implementation here just checks for GET requests with a file extension. This means a couple things:
Per the TODO comment, I investigated using the manifest to identify requests for static assets, but found this to be problematic. Perhaps it is an issue with my individual build tooling or configuration, but the manifest only includes js/css assets. I think a better approach would be to recursively scan the |
I think we should look for |
@benmccann Agreed. I can implement this over the weekend so that we can get this in. I have a question about another feature enhancement though. I'd like to add support for a cloudflare worker hook. Should I implement that in this PR or would you prefer that I open another once this has been merged? Thanks. |
It's probably easier to review as separate PRs |
Thank you! Pages probably shouldn't have their own option here. There's already a place to set headers globally, and that's The regex stuff is definitely a no-go :) Could you remove that so that this PR is purely about caching? The way to check if a request is for an asset would be to check the path against a list of them. We have such a thing here... kit/packages/kit/src/core/build/index.js Line 74 in 3e30a1b
_app files and b) the list of prerendered pages, if any. That could happen in a separate PR.
Speaking of a), since those generated files are hashed, they can be treated as immutable, and should probably automatically get a Speaking of b), we might need a way to differentiate between prerendered pages and other assets in the KV store. (We might want to distinguish between different assets altogether — e.g. a longer TTL for So in summary, perhaps an API like this makes sense? import adapter from '@sveltejs/adapter-cloudflare-workers';
export default {
kit: {
adapter: adapter({
browserTTL: {
prerendered: 60,
static: 24 * 60 * 60
},
edgeTTL: {
prerendered: 60,
static: 24 * 60 * 60
}
})
}
}; |
Any plans to get this functionality over the line? Been a few months since last activity. |
I'm happy to take a stab at this. I'm going to simply kit/packages/kit/src/core/build/index.js Line 72 in 3e30a1b
import { init, render, manifest } from '../output/server/app.js';
if (manifest._app[path])
// Should cache immutable
else if (manifest.assets[path])
// Should cache but not immutable
... I'm not sure how I should handle prerendered pages. |
Reflecting further on this, many adapters can and should set |
New breaking change here
null
. Otherwise defaults will apply. Any static assets without file extensions will break.I have been using svelte-kit to rebuild my personal site/blog and noticed a few areas for improvement.
Slow page response
The problem here is having to wait for asset fetch to fail before moving on to try to render. The solution I put in place is more of a stop-gap. It is just checking for a file extension at the end of the request path.
By adding this gate, page request time dropped by 60-80%. However, static assets without file extensions will break. I'd like to improve upon my approach and would appreciate feedback here.
Static assets are not returned with cache-control header
The default svelte-kit adapter returns this header so that browser cache can be utilized.
Refer to the updated README documenting the properties and their purpose.
Testing
I did not see tests in any of the adapters, don't mind writing some, but would appreciate input here.
That aside. I'm currently using this adapter code on a production site without issues.