Conflict between service worker and CloudFront?
See original GitHub issueIām deploying my React app to S3 behind a CloudFront distribution. With my particular process, I copy all the files to S3, and then copy index.html
in the following manner:
aws s3 cp --cache-control 'public, no-cache, must-revalidate, proxy-revalidate, max-age=0' ./build/index.html $APP_BUCKET
The Cache-Control
used to just be max-age=0
, but I ran into problems with aggressive caching and added more options. I never want index.html
to be cached, otherwise when I release updates, users would still get the old index.html
pointing to the old JS files.
Now Iām wondering if the service worker is somehow getting in the way. Should I remove it since Iām using CloudFront? Or is there a better way than what Iām doing to make sure that when I deploy a code update, that users will get it next time they reload or hit the site?
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to configure Service Worker with React to prevent ...
You should always cache it on Cloudfront edge since you can run invalidation requests to purge cloudfront edge cache after a new deployment....
Read more >Troubleshoot issues with CloudFront custom object caching
If your CloudFront distribution isn't caching based on the custom values that you set on cache behaviors, then check the origin. Verify whether...
Read more >Install and Configure Amazon CloudFront for Sites Hosted at ...
Amazon CloudFront is a highly-configurable CDN. Learn how to install and configure it for best compatibility with Kinsta's CloudflareĀ ...
Read more >Production deploy of a Single Page App using S3, CloudFront ...
Building and uploading content to AWS S3 with the correct HTTP Cache headers so that ... To support deep links, the main Distribution...
Read more >Deploying React and Angular Single Page Applications to ...
Do not cache service-worker.js file: If you are using PWA, ... Let's now dive into the relationship between CloudFront and S3.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I set the CloudFront TTLs (default, min, max) all to 0. Thereās still odd behavior going on. If I redeploy my updated app and then open it up, I see in the console a message telling me to refresh, that thereās an update. I do so, and I see the code update, but the log says once again to refresh to get an update. That behavior seems wrong.
Any insight on how to properly deploy to S3 + CloudFront would be really helpful!
UPDATE:
I think I got it. Iāve left CloudFront cache settings alone (using origin headers, etc), and changed my deployment to single out these two files now:
The service worker itself was getting cached, which is problematic.
But someone let me know if thereās a better way still. š
@lalzada I was working in a test version actually, so I had no real users actually. It was a solution just for me to avoid waiting 1 day.
Thanks for your question, Iāll edit my comment š