Search code examples
symfonycachingcaddy

Clear users' browser cache upon deploy symfony2


I have a problem with my users' cache with my symfony2 application: every time I deploy updates to the application, users have to clear their browser cache in order to get the new styles and javascript.

It has started happening after I've set up an architecture with an AWS ECS cluster running 2 servers with my docker images. And I have a Caddy reverse proxy that load-balances these two servers.

I don't understand where the problem is occurring, it is Caddy caching the requests, is it Twig or do you have any other ideas?

Obviously I run php bin/console cache:clear --env=prod when deploying.


Solution

  • Since we are talking about browser cache (css, js files) you should take a look at Symfony asset versioning.

    http://symfony.com/blog/new-in-symfony-2-7-the-new-asset-component

    In you config/parameters you can specify the version of your assets.

    If you want to do this automatically you can connect asset version with you git commit like in the following like but your app should be able to run exec() command on your server.

    http://blog.lavoie.sl/2012/10/automatic-cache-busting-using-git-in-symfony2.html