Skip to content
April 12, 2011 / kiranpatils

Media Library status code 200 Vs 304

Challenge:

If you are seeing some unexpected behavior from the Sitecore Media Request Handler which takes care of responding to requests for items held in the Sitecore Media Library. Media library items were being returned in full every time that they were requested, each returning a HTTP 200 response status code. Instead they should return HTTP 304 code, if requested second time.

Solution:

After reading a bit, we found that

Its Sitecore’s BUG:

Further digging with Lutz Roeder’s excellent Reflector tool showed that the If-Modified-Since request header field was not being responded to correctly by the MediaRequestHandler. The If-Modified-Since request header is a HTTP-date value whose time component is in the format HH:MM:SS (i.e. no milliseconds). This header field value is used by the Modified method within the MediaRequestHandler to compare to the System.DateTime value that the media library item was last updated. As a System.DateTime value includes a milliseconds component the equality check fails for the majority of media library requests and as a result the item is downloaded to the browser in full.
[Source : http://kevinobee.wordpress.com/2010/11/28/http-304-response-bug-in-sitecore-mediarequesthandler/]

It has been fixed in Released Sitecore CMS 6.4.1 rev.110324 (6.4.1 Update-1). – And as per my knowledge it is not recommended version.

Sitecore parsed and compared timestamps in the “If-Modified-Since” HTTP header incorrectly, causing the server to never return a “304 Not Modified” response. This prevented browsers from using their cached versions of media files and caused unnecessary data to be transferred from the server to the client. (320278, 325114)
[Source : http://sdn.sitecore.net/Products/Sitecore%20V5/Sitecore%20CMS%206/ReleaseNotes/ChangeLog.aspx]

Alternatively, You can write your custom Media Handler which modifies the way “If-Modified-Since” HTTP header is used

http://sitecore.alexiasoft.nl/2007/09/13/adding-your-own-httphandler-to-sitecore-53/
http://www.fishofprey.com/2010/12/sending-sitecore-mediastream-through.html

What I would suggest you is that Download Sitecore 6.4.1 install it on local box. Using Reflector check how It’s MediaHandler works. And just pick up that code, and include it in your custom media handler and incorporate in your current Sitecore version.

Happy Media Handling! 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: