Go, the ETag should serve your needs without further effort. ETags should work by default, so you really don't need to do anything, but to avoid problems in multi-server environments, you can configure your ETags to calculate from file size and last timestamp. For example, replace existing directives with the following line in your .htaccess or Apache configuration:
FileETag MTime Size
The ETag effectively expires the cached image automatically when the image changes. The disadvantage is that the browser still requests a resource with each request, so it is slightly less efficient than the expiration directives used. ETags, on the other hand, avoid the described problem.
However, if you have already used one of the cache directives, as described in your question, and set the Expires value to something far in the future, then any browser that requested the file in the past will not check it again for some time. You can hack this by adding a trivial query string, such as ?cache=123 , to the url to make it different (thus bypassing the cache). Then you can count on the ETag mechanism in the future.
source share