I want to take my application to offline mode, and I want to register a service worker. My files are hosted in AWS S3 and I've created worker.js in the root of my bucket. I may need to return custom header "Service-Worker-Allowed" in response from AWS S3 for worker.js Currently custom headers are requiring to have x-amz-meta headers, which I can not use. Are there anyway to add that header by using Cloudfront or Cloudfare? Or any other suggestions?
You can not set custom response headers with s3 or cloudfront.
You have 2 possible workarounds when using AWS.
lambda@edge
.Option 2, lambda@edge
is a simpler solution. It is designed to run a lambda function from a cloudfront edge node. You can use lambda@edge to run custom javascript code. You can configure your code to run before a http request is sent to cloudfront or after a http response is received from cloudfront. This allows you to set custom request or response headers. See https://medium.com/@tom.cook/edge-lambda-cloudfront-custom-headers-3d134a2c18a2 for a good write-up on how to do this.
In AWS S3, click on object and go to its settings, there Metadata section where you can add custom headers. Simply click on add metadata.
This can also be done programmatically while uploading data. All api supports additional metadata.
It's not possible at the moment. S3 only allows you to add header by prefix x-amz-meta and some standard header for caching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With