1

I have a Django + Guicorn + Nginx project. My problem is that every time after I had deployed a new change on EC2, the new change wouldn't get updated in the browser unless I deleted the cache locally. I don't really have a clue as of why this is the case and how I am supposed to implement my project to prevent this problem.

YAL
  • 523
  • 2
  • 5
  • 17
  • A temporary fix might be to disable your cache: take a look at this [link](http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development) – John F. Jan 15 '17 at 07:17
  • @JohnF. I am deploying the product to users, and I couldn't ask them to disable their cache. Hence, looking for a production level solution. – YAL Jan 15 '17 at 07:27
  • If, rather than deleting the cache locally, you restart the browser, does it work? – Antonis Christofides Jan 15 '17 at 08:29

1 Answers1

2

If we are talking about JS, the issue is that you are not bundling your assets correctly to support what is often termed “cache-busting.” Frameworks such as gulp, webpack and django_assets all have cache busting ready for you so that when you are ready to deploy, your users do not have to drop cache. For example, in django_assets/webassets the URL to your bundled JS file will be suffixed with a hash parameter so that when the contents of the JS file change, the URL will also change.

For the same reason, you have configured your web server to send out your media files with a so called far future expires header: Your web server sets the Expires header to some date many years in the future. Your user’s browser will never spend any time trying to retrieve an updated version.

What if you actually deploy an update to your site? Now you need to convince the browser to download new versions of your assets after all, but you have just told it not to bother to check for new versions. You work around this by modifying the URL with which the asset is included.

2ps
  • 12,175
  • 2
  • 17
  • 39
  • 1
    yes, that would do the trick +1. The OP can just rename the offening js file as a temporary fix if these cache busting frameworks haven't been installed. – e4c5 Jan 15 '17 at 12:00