Borja
Borja

Reputation: 243

<video> tag HTML5 cache in Firefox and Opera

I´m having a problem with the cache in Firefox and Opera to use the HTML5 tag .

My page has a button that generates a new video in the server when it´s clicked (always the same name), and when the video is generated, is showed in the page with video.../video.

The problem is that Firefox and Opera always show the first version of the video in the page, and the last version (correctly) if I enter to the video URL directly.

I have tried deleting cache, using "meta http-equiv="Cache-control" content="no-cache" ", but it´s useless.

In Chrome and Safari it works perfectly.

Any idea?

Thanks

Upvotes: 1

Views: 5822

Answers (1)

Jörn Berkefeld
Jörn Berkefeld

Reputation: 2579

3 options:

  1. send proper cache-control headers for the video-file. this would be done via htaccess file or web.config file (Apache / IIS). while essentially a good solution it might still fail in some browsers
  2. attach a timecode to the path like this: http://mydomain.com/mypath/myvideo.mp4?t=13591239123
  3. always use a new name for the video-file - e.g. by counting the generated videos and numbering them sequentially

option 3 together with a cronjob that deletes old videos is probably best - else two users looking at your page at the same time would overwrite each others video.

option 1 / 2 are fine for a single-user environment.

option 2 would reset the path of your <video id='myvideo'> element upon completion of generating the new video:

document.getElementById('myvideo').setAttribute("http://mydomain.com/mypath/myvideo.mp4?t="+(+new Date());

note that this solution only deals with one source file. for this to work in all browsers you need mp4 and webm (or ogv) files --> two video files compare http://caniuse.com/webm and http://caniuse.com/mpeg4

Upvotes: 6

Related Questions