diff --git a/API.md b/API.md
index 3e63de57..108363cb 100644
--- a/API.md
+++ b/API.md
@@ -3053,6 +3053,7 @@ const nextjsCachePolicyProps: NextjsCachePolicyProps = { ... }
| serverCachePolicy
| aws-cdk-lib.aws_cloudfront.ICachePolicy
| *No description.* |
| staticCachePolicy
| aws-cdk-lib.aws_cloudfront.ICachePolicy
| *No description.* |
| staticClientMaxAgeDefault
| aws-cdk-lib.Duration
| Cache-control max-age default for static assets (/_next/*). |
+| staticResponseHeaderPolicy
| aws-cdk-lib.aws_cloudfront.ResponseHeadersPolicy
| *No description.* |
---
@@ -3100,6 +3101,16 @@ Default: 30 days.
---
+##### `staticResponseHeaderPolicy`Optional
+
+```typescript
+public readonly staticResponseHeaderPolicy: ResponseHeadersPolicy;
+```
+
+- *Type:* aws-cdk-lib.aws_cloudfront.ResponseHeadersPolicy
+
+---
+
### NextjsDefaultsProps
Defaults for created resources.
diff --git a/src/NextjsDistribution.ts b/src/NextjsDistribution.ts
index cc7e1308..81ed75e9 100644
--- a/src/NextjsDistribution.ts
+++ b/src/NextjsDistribution.ts
@@ -30,6 +30,7 @@ export interface NextjsDistributionCdkProps {
}
export interface NextjsCachePolicyProps {
+ readonly staticResponseHeaderPolicy?: ResponseHeadersPolicy;
readonly staticCachePolicy?: cloudfront.ICachePolicy;
readonly serverCachePolicy?: cloudfront.ICachePolicy;
readonly imageCachePolicy?: cloudfront.ICachePolicy;
@@ -296,20 +297,22 @@ export class NextjsDistribution extends Construct {
private createStaticBehaviorOptions(): cloudfront.BehaviorOptions {
const staticClientMaxAge = this.props.cachePolicies?.staticClientMaxAgeDefault || DEFAULT_STATIC_MAX_AGE;
// TODO: remove this response headers policy once S3 files have correct cache control headers with new asset deployment technique
- const responseHeadersPolicy = new ResponseHeadersPolicy(this, 'StaticResponseHeadersPolicy', {
- // add default header for static assets
- customHeadersBehavior: {
- customHeaders: [
- {
- header: 'cache-control',
- override: false,
- // by default tell browser to cache static files for this long
- // this is separate from the origin cache policy
- value: `public,max-age=${staticClientMaxAge},immutable`,
- },
- ],
- },
- });
+ const responseHeadersPolicy =
+ this.props.cachePolicies?.staticResponseHeaderPolicy ??
+ new ResponseHeadersPolicy(this, 'StaticResponseHeadersPolicy', {
+ // add default header for static assets
+ customHeadersBehavior: {
+ customHeaders: [
+ {
+ header: 'cache-control',
+ override: false,
+ // by default tell browser to cache static files for this long
+ // this is separate from the origin cache policy
+ value: `public,max-age=${staticClientMaxAge},immutable`,
+ },
+ ],
+ },
+ });
const cachePolicy = this.props.cachePolicies?.staticCachePolicy ?? cloudfront.CachePolicy.CACHING_OPTIMIZED;
return {
...this.commonBehaviorOptions,