-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(vercel): isr * bypass token * exclusion of certain paths * add test * remove search params in dev mode * Apply suggestions from code review Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * Apply suggestions from code review * Apply suggestions from code review * fix missing await * escape src for regex * cleanup * revalidate -> expiration * update type docs * always exclude /_image * add changeset * Apply suggestions from code review * always create serverless function for /_image * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Apply suggestions from code review --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
- Loading branch information
1 parent
88628a4
commit e2fe51c
Showing
10 changed files
with
310 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
"@astrojs/vercel": minor | ||
--- | ||
|
||
Introduces a new config option, `isr`, that allows you to deploy your project as an ISR function. [ISR (Incremental Static Regeneration)](https://vercel.com/docs/incremental-static-regeneration) caches your on-demand rendered pages in the same way as prerendered pages after first request. | ||
|
||
To enable this feature, set `isr` to true in your Vercel adapter configuration in `astro.config.mjs`: | ||
|
||
```js | ||
export default defineConfig({ | ||
output: "server", | ||
adapter: vercel({ isr: true }) | ||
}) | ||
``` | ||
|
||
|
||
## Cache invalidation options | ||
|
||
By default, ISR responses are cached for the duration of your deployment. You can further control caching by setting an `expiration` time or prevent caching entirely for certain routes. | ||
|
||
### Time-based invalidation | ||
|
||
You can change the length of time to cache routes this by configuring an `expiration` value in seconds: | ||
|
||
```js | ||
export default defineConfig({ | ||
output: "server", | ||
adapter: vercel({ | ||
isr: { | ||
// caches all pages on first request and saves for 1 day | ||
expiration: 60 * 60 * 24 | ||
} | ||
}) | ||
}) | ||
``` | ||
|
||
### Manual invalidation | ||
|
||
To implement Vercel's [Draft mode](https://vercel.com/docs/build-output-api/v3/features#draft-mode), or [On-Demand Incremental Static Regeneration (ISR)](https://vercel.com/docs/build-output-api/v3/features#on-demand-incremental-static-regeneration-isr), you can create a bypass token and provide it to the `isr` config along with the paths to exclude from caching: | ||
|
||
```js | ||
export default defineConfig({ | ||
output: "server", | ||
adapter: vercel({ | ||
isr: { | ||
// A secret random string that you create. | ||
bypassToken: "005556d774a8", | ||
// Paths that will always be served fresh. | ||
exclude: [ "/api/invalidate" ] | ||
} | ||
}) | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.