Besides the actual issue there is also an architecture question that I want to raise here. I'm by no means a Varnish expert, but I have read the following short blog article that makes a lot of sense to me: https://ma.ttias.be/stop-caching-static-files-in-varnish/
He argues that static assets like JS/CSS/Images should not be cached by Varnish since they only consume memory but do not really cause load on the webserver if not cached. Also, they give wrong ideas about the cache hit rate in the Varnish statistics.
Is there a good reason for why the exported Magento2 varnish config makes it cache such static assets? If not, I want to suggest changing that.
This could be a bug that I am experiencing with Varnish and M2
Same here with Magento 2.1.2 EE
Can confirm this in 2.1.3. Have same issues. Always need to purge the Varnish cache from the command line. Very irritating.
As a temporary workaround you can find in the vcl file the line where it caches the static assets and change with return(pass);. The static assets are now served directly by the webserver instead of varnish.
@giacmir Don't think that is a good idea :-)
I'd rather have the bug fixed, but I appreciate any help with a workaround for now
This workaround goes in the direction of my last question about why static assets are cached in the first place.
@PieterCappelle what makes you say that that wouldn't be a good idea?
Any updates on this Magento? This is a major bug for any production site using Varnish
Magento tries to propagate static resource as far as possible in web. Built-in php adapter and installations without Magento_PageCache module store static resouces in browser cache. Thus described case is a bug and Varnish shouldn't handle static content (content must go from webserver to browser directly and cached there). However, this doesn't solve your issue and even make it worse.
Usually, such cases are solved by content versioning. Magento is not an exception. We adding suffixes to filename in case when file with the same name already exists. It allows to deliver fresh files to the end user. For your case, I would recommend to change the picture name and notify productRepository with new picture's path.
We will put appropriate tasks in backlog in order to remove inconsistencies between varnish and php page cache
Internal ticket MAGETWO-33342 is in our issue backlog.
Thanks
Try to add ;
varnishadm "ban req.url ~ "/" "
to your cache:clean task, to manually purge the static file cache.
works for me.
If you are using a public CDN service, you will have the same problem. The solution is to change the change the image with one with different filename.
issue MAGETWO-33342 was fixed and delivered to mainline.
Thanks!
Most helpful comment
As a temporary workaround you can find in the vcl file the line where it caches the static assets and change with
return(pass);. The static assets are now served directly by the webserver instead of varnish.