Code - Alpha Solutions

Yep, this is old news but apparently lots of people don’t know about this.

28.2.19

BY GEYKEL MORENO

As you may know, when you replace an existing media item image with another one in Sitecore, if the new image is the same size as the older one, or if you are not appending the image dimension on the media item URL, you may run into a browser caching issue. That’s because even when you replace the image, the URL is the same. Therefore the browser will likely render the older version of the image because it is probably cached. If you’re using a CDN and think you’re safe from this issue, you’re not. This issue usually also affects your CDN, since it won’t be able to pull the updated image from the CD – again, because it is the same URL (at least until the CDN cache policy expires anyway).

So I was running into these issues and I noticed that the most common solution suggested for this is to override the Media Provider in order to append the revision and hash values as query string parameters to the media item URL. That way, every time the media item is updated, a new URL will be generated by the Media Provider for that media item, so cache problem solved!

This common solution is valid and great, but the good news is that starting on Sitecore 8.2 Update 5 there is a built-in setting that will do that for you:

<setting name="Media.AlwaysAppendRevision" value="false"/>

By default its value is false, if you set it to true you will start to see your media items URL looking something like this:

http://example.com/-/media/Products/Bags/
B581.png?rev=bcf6a8ff80f74399bcdf02410
7173115&hash=633D10816CD7E62D5E86
23D217F6296402D5B7BE

Note how out of the box, you will now get revision and hash values added to the URL.

Hope this helps!