-
Notifications
You must be signed in to change notification settings - Fork 512
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
perf(netlify, netlify-edge): exclude static paths from server handler #2822
perf(netlify, netlify-edge): exclude static paths from server handler #2822
Conversation
The netlify preset was already using `preferStatic: true` which lets existing static assets take precedence over the function, but this now also avoids a function invocation for static paths that don't exist, i.e. this avoids an unnecessary dynamic 404 that could be served directly from the CDN. The `netlify-edge` preset wasn't excluding anything, so this addresses both the 404 case and the existing asset case. The 404 case is important because browsers frequently attempt to request hashed assets from previous deploys that have been invalidated. There's no reason for this to go through functions, since we know that the whole parent path is static.
5369c48
to
ce72ea3
Compare
Thanks for the PR dear @serhalp It seems main blockers on PR are addition of tests (which are so nice) -- although i don't want the main improvement to be missed for 2.10 release, perhaps we can extract work on tests to an additional PR? Main addition seems could be tested easily both manually or with a simple unit test for |
Backporting nitrojs#2822 to the netlify-legacy preset. Since it's using "v1" Netlify Functions (https://docs.netlify.com/functions/lambda-compatibility), it doesn't have access to `excludedPath` and `preferStatic`, so we implement this with redirects.
Backporting nitrojs#2822 to the netlify-legacy preset. Since it's using "v1" Netlify Functions (https://docs.netlify.com/functions/lambda-compatibility), it doesn't have access to `excludedPath` and `preferStatic`, so we implement this with redirects.
Backporting nitrojs#2822 to the netlify-legacy preset. Since it's using "v1" Netlify Functions (https://docs.netlify.com/functions/lambda-compatibility), it doesn't have access to `excludedPath` and `preferStatic`, so we implement this with redirects.
Backporting nitrojs#2822 to the netlify-legacy preset. Since it's using "v1" Netlify Functions (https://docs.netlify.com/functions/lambda-compatibility), it doesn't have access to `excludedPath` and `preferStatic`, so we implement this with redirects.
and unit test it also, ensure the right URL format on paths
@pi0 I made all the requested changes. Here's a manual QA against a nuxt site (opted in to nuxt v4 + 2014-10-31 compat date for new preset):
|
And for good measure here's one against
|
Thanks β€οΈ |
π Linked issue
N/A - discussed on Discord
β Type of change
π Description
The netlify preset was already using
preferStatic: true
which lets existing static assets take precedence over the function, but this now also avoids a function invocation for static paths that don't exist, i.e. this avoids an unnecessary dynamic 404 that could be served directly from the CDN.The
netlify-edge
preset wasn't excluding anything, so this addresses both the 404 case and the existing asset case.The 404 case is important because browsers frequently attempt to request hashed assets from previous deploys that have been invalidated. There's no reason for this to go through functions, since we know that the whole parent path is static.
This PR also adds tests for the
netlify-edge
preset, which were missing. They're mostly copied from thenetlify
preset tests.π Checklist