Skip to content

Instantly share code, notes, and snippets.

@iDVB
Created June 17, 2021 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iDVB/fbcf30de3ff37e9a450824cf679b9e54 to your computer and use it in GitHub Desktop.
Save iDVB/fbcf30de3ff37e9a450824cf679b9e54 to your computer and use it in GitHub Desktop.
Gatsby Cache-Control in CDK
const deployment1 = new s3deploy.BucketDeployment(this, 'BucketDeployment1', {
sources: [
s3deploy.Source.asset(props.siteAssetsPath, {
ignoreMode: cdk.IgnoreMode.GIT,
exclude: ['*.*', '!*.js', '!*.css', 'sw.js', '!static/**', '_redirects'],
}),
],
memoryLimit: 512,
cacheControl: [s3deploy.CacheControl.fromString('public,max-age=31536000,immutable')],
destinationBucket: primaryBucket,
prune: true,
})
const deployment2 = new s3deploy.BucketDeployment(this, 'BucketDeployment2', {
sources: [
s3deploy.Source.asset(props.siteAssetsPath, {
ignoreMode: cdk.IgnoreMode.GIT,
exclude: [
'*.*',
'!*.html',
'!page-data/**/*.json',
'!sw.js',
'!robots.txt',
'!sitemap/**',
'!_redirects',
],
}),
],
memoryLimit: 512,
cacheControl: [s3deploy.CacheControl.fromString('public,max-age=0,must-revalidate')],
destinationBucket: primaryBucket,
prune: false,
})
const deployment3 = new s3deploy.BucketDeployment(this, 'BucketDeployment3', {
sources: [
s3deploy.Source.asset(props.siteAssetsPath, {
ignoreMode: cdk.IgnoreMode.GIT,
exclude: [
'*.html',
'page-data/**/*.json',
'*.js',
'*.css',
'static/**',
'robots.txt',
'sitemap/**',
'_redirects',
],
}),
],
memoryLimit: 512,
destinationBucket: primaryBucket,
prune: false,
})
deployment3.node.addDependency(deployment2)
deployment3.node.addDependency(deployment1)
deployment2.node.addDependency(deployment1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment