Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Add 'Cache-Control' header for static files on S3 #57

Merged
merged 2 commits into from
Apr 12, 2020

Conversation

ferdinandfrank
Copy link
Contributor

What issue does this PR address:
I recently did an audit on my page and noticed that the uploaded static assets on S3 do not have an efficient cache policy, which decreases the performance of a page. See the screeenshot:

image

How this PR fixes this issue:
I added the Cache-Control metadata to the uploaded static assets so AWS will add a Cache-Control header to the response of a requested static file. I selected a TTL of 1 year for the files since all static files receive a unique content hash as the file name by the Nuxt build, whereby a file would receive a new name as soon as its content changes. See here for details: https://nuxtjs.org/api/configuration-build#filenames

Further improvements:
It might be useful to have different cache TTLs for different file types. I couldn't think of a use case but there might are some. Additionally, it could make sense to make the TTL configurable in the serverless custom vars. Tell me what you think :)

@wan2land wan2land merged commit 68891b5 into wan2land:master Apr 12, 2020
@wan2land wan2land mentioned this pull request Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants