Under what conditions will the browser cache <video> files?

22,678

Solution 1

The following works to instruct the browser to cache the files. The last line was necessary to make the server deliver webm files with the correct header MIME type.

# Expires is set to a point we won't reach,
# Cache control will trigger first, 10 days after access
# 10 Days = 60s x 60m x 24hrs x 10days =  864,000
<FilesMatch "\.(webm|ogg|mp4)$">
Header set Expires "Mon, 27 Mar 2038 13:33:37 GMT"
Header set Cache-Control "max-age=864000"
</FilesMatch>
AddType video/webm .webm

Solution 2

The HTML5 spec is not strict about what a browser must do with caching video files - it just suggests what is "reasonable", so theoretically different browsers could have different behaviour.

Web developers can try to control video caching using the preload attribute on the <audio> or <video> element like this:

preload=none The user might not watch the video (i.e. better not to preload)

preload=metadata The user might watch the video (i.e. better to just download information about the video (size, duration, etc.))

preload=auto The user is likely to watch the video (i.e.probably a good idea to preload and cache the video)

As I said, the spec does not enforce this so browsers could ignore the preload values if they choose. One example could be if a browser detects a slow or unstable connection and therefore refuses to preload, although I don't know of any browsers that do this at present.

More information on the preload attribute is here: http://www.w3.org/TR/html5/video.html#attr-media-preload

Share:
22,678
Matrym
Author by

Matrym

Updated on February 28, 2020

Comments

  • Matrym
    Matrym about 4 years

    Under what conditions will the browser cache files? Sometimes it does, sometimes it doesn't. If no one here knows, my next step will be to test the various file format, file size, and htaccess scenarios.

    If you don't know, can you think of any other variables that you'd recommend testing?

    Thanks in advance!

  • Matrym
    Matrym about 13 years
    Thanks for the detailed and thought-out response. I might have been unclear in my question, though. When I said cache, what I'm referring to is the video file not needing to be downloaded again if the user returns to the page. This is sometimes, but not always the case. An answer like "It does for ogg in FFX, but nowhere in chrome" would helpful, as would something like "It will everywhere if you put this line in your htaccess file". Thanks!
  • tagawa
    tagawa about 13 years
    Ah, my misunderstanding. In that case, I'm not really sure and wouldn't know where to find out other than through trial and error. Sorry - probably not the answer you were hoping for.