Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mrcoles/197542d1269784b30810da8fc3ecc974 to your computer and use it in GitHub Desktop.
Save mrcoles/197542d1269784b30810da8fc3ecc974 to your computer and use it in GitHub Desktop.
Sample file caching custom headers to add to an AWS Amplify build-settings.yml file
frontend:
customHeaders:
# cache static assets! (can I just use a glob for this, e.g., '**/*.{js,css,gif,ico,jpg,png,svg,mp4,webm}' ?)
# js
- pattern: '**/*.js'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# css
- pattern: '**/*.css'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# images
- pattern: '**/*.gif'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
- pattern: '**/*.ico'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
- pattern: '**/*.jpg'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
- pattern: '**/*.png'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
- pattern: '**/*.svg'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
# videos
- pattern: '**/*.mp4'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
- pattern: '**/*.webm'
headers: [ { key: 'Cache-Control', value: 'public,max-age=31536000,immutable' } ]
@mrcoles
Copy link
Author

mrcoles commented Oct 19, 2019

This is a gist representing a comment I made on the AWS Amplify forums about how to cache static files properly: https://forums.aws.amazon.com/thread.jspa?threadID=306225#jive-message-918563

The idea is to add this customHeaders section to the frontend part of your build-settings.yml for your AWS Amplify project in order to aggressively cache static assets. This assumes that the content you’re serving for these suffixes is expected to be cached forever and any changes will have a new path, e.g., content-based hashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment