Content changes to media items may not be reflected in the browser immediately


Description

When new content is attached to an already published media item and the media item is published again, the content change might not be reflected in the browser immediately when you access the media using its URL.

This happens because the media is cached in the browser for the time specified in the MediaResponse.MaxAge setting. If a browser has already accessed the media item, it may not perform any requests to the server and may retrieve the media item from its cache until the cached version expires.

Solution

To force the browser to always check whether the media item has changed since the last request, and download a new version if necessary, you need to set the MediaResponse.MaxAge setting in the web.config file to 00:00:01. This makes Sitecore set Cache-Control: max-age and Expires headers of the HTTP response for media request to 1 second.

Please note that the purpose of the Cache-Control: max-age and Expires headers is not only to reduce the load of downloads from the server but also to reduce the number of HTTP requests to the server. Therefore, please consider this when you change the MediaResponse.MaxAge configuration. You might want to set a higher value than 00:00:01, depending on your requirements.

Please also note that if you set the MediaResponse.MaxAge setting to 00:00:00, then the Cache-Control: max-age and Expires headers will not be added to the response and the browser will decide whether to emit new requests to the server or not on its own, and you will not be able to control it.