You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`/_next/image`| Image optimization | - | image optimization function |
132
-
|`/_next/data/*`| data requests | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific)| server function |
133
-
|`/api/*`| API | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific)| server function |
134
-
|`/*`| catch all | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific)| server function |
127
+
| Behavior | Requests | CloudFront Function | Origin |
|`/_next/image`| Image optimization | - | image optimization function |
132
+
|`/_next/data/*`| data requests | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific)| server function |
133
+
|`/api/*`| API | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific)| server function |
134
+
|`/*`| catch all | set `x-forwarded-host`<br />[see why](workaround#workaround-set-x-forwarded-host-header-aws-specific). Also [see this](workaround#workaround-nextserver-does-not-set-cache-headers-for-html-pages)| server function |
Copy file name to clipboardExpand all lines: pages/aws/v2/advanced/workaround.mdx
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,12 +113,15 @@ export function middleware(request: NextRequest) {
113
113
114
114
As mentioned in the [Server function](./architecture#server-lambda-function) section, the server function uses the `NextServer` class from Next.js' build output to handle requests. However, `NextServer` does not seem to set the correct `Cache Control` headers.
115
115
116
-
To work around the issue, the server function checks if the request is for an HTML page, and sets the `Cache Control` header to:
116
+
To work around the issue, the server function checks if the request is for a fully static HTML page from page router (i.e. without `getStaticProps`), and sets the `Cache Control` header to:
If you plan on using fully static HTML pages, you should also add the `x-middleware-prefetch` header to cloudfront cache headers to avoid cloudfront caching an empty response when this header is set.
123
+
You can also just add an empty `getStaticProps` function to your page, which will set the correct cache headers.
124
+
122
125
#### WORKAROUND: `NextServer` does not set correct SWR cache headers
123
126
124
127
`NextServer` does not seem to set an appropriate value for the `stale-while-revalidate` cache header. For example, the header might look like this:
0 commit comments