If one needs to serve static files evenly fast to any device in the world then they are probably thinking about CDN.
Plan
- create S3 bucket
- create a “distribution” in AWS CloudFront for that bucket (how many times my colleagues keep calling it CloudFlare?)
Caveats
- to serve index.html without specifying this in the path - add special function to CloudFront
function handler(event) {
var request = event.request;
var uri = request.uri;
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.
else if (!uri.includes('.')) {
request.uri += '/index.html';
}
return request;
}
- late CSS loading in Firefox
<head>
<link rel="stylesheet" href="css/styles.css" />
<script>
/*to prevent Firefox FOUC, this must be here*/
let FF_FOUC_FIX;
</script>
</head>
-
serve compressed files (this doesn’t work - need to try in the console)
-
when new files uploaded to the bucket - create invalidation in CloudFront