Hack to download files from an S3 bucket when browser cache won't restart.

An issue today was that eFinalDate was accessing the S3 bucket, and the images were being cached, so they wouldn't download the new settings on the bucket. This was on a customer's computer.  Fortunately, he was great to work with. Patient, and understanding

I was trying to call the url from angular using $http.get(s3-amazon-bucket-url).

We tried the following
  • Clear the cache. It worked, but once the image was recached, it wouldn't work.
  • Clear the cache. For whatever reason, the customer's cache wouldn't clear.
  • Go to developer settings, click on Network, and check Disable cache. This worked while the developer window was open, but not once it was closed.
  • Tried Ctrl-F5 to do a hard refresh
None of these worked. Sometimes the change would be temporary, other times not.

Finally, we tried appending a random string on the end of the get url. so it looked like : https://s3-us-west-1.amazonaws.com/efinaldate-images/prod/orders/1/1/eFinalDate-230-sized-21e6088c.jpg?2093930290393 (tied to miliseconds).

This actually worked. 

We did a big no-no, and pushed this one line change on the server in the middle of the day 😁
var url = order.processed_url + '?' + Date.now();

And, well, it worked. This is a total hack, and recognizes that the cache is based on the url, but the file is only based on the first part of the url. The url is now different, so it asks the server for the latest version of the file.

No comments:

Post a Comment

XAMPP phpMyAdmin subdomain on localhost

Create a localhost subdomain for phpMyAdmin on XAMPP Open xampp\apache\conf\extra\http-vhosts.conf and append the following (modify the Docu...