I am using s3 bucket to host my web site. Whenever I release a new version of my web site, I want all clients download it from s3 instead of reading from their browser cache. I know I can set up an expire time for the object saved on s3 bucket but it is not an idea solution since users have to use the cached content for a period of time. Is there a way to force browser to download the content if they are changed in s3 bucket?
Add a comment |
1 Answer
Irrespective of whether you are using s3 bucket for hosting or any other hosting server, caching can be controlled by appending hash number to file name.
For example your js file bundle name should be like bundle.7e2c49a622975ebd9b7e.js. When you deploy it again it will change to some other hash value bundle.205199ab45963f6a62ec.js. By doing this, browser automatically knows that, new file has arrived and should be downloaded again.
This can be easily done using any popular bundlers like grunt, gulp, webpack. webpack example
1 Comment
Joey Yi Zhao
I know that webpack can generate a file with a hash name. The entry for my website is
index.html. Browser open my website by domain url. If browser caches the index.html file and it won't pickup the new bundle js file right?