Androidicus
Androidicus

Reputation: 1748

Prevent Browser File Caching

I need to disable caching for single files in all browsers. I have a website that generates small video clips. There is a preview stage where the results can be watched.

An mp4 called preview.mp4 is displayed. When the user goes back, edits the video and wants to preview it again, the old preview.mp4 is being displayed even though the file on the server is changed.

How can I prevent the caching of this video file? Or what are the other ways to fix it?

Note: it's a single page application so I don't reload any HTML files. Only PHP content. Hence the headers I set, are not useful in this scenario:

<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="cache-control" content="no-store" />

Thanks.

Upvotes: 3

Views: 5932

Answers (3)

Ave Maria - Hail Mary
Ave Maria - Hail Mary

Reputation: 69

Try adding a cache key

preview.mp4?cachekey=randNum

Where randNum can be a timestamp or you use a random number generator to generate randNum.

Upvotes: 1

Curtis
Curtis

Reputation: 103388

It's not the web page itself you should be concerned about, but the mp4 file which is downloaded and cached separately.

Ensure the response headers of the mp4 file prevent browser caching.

Cache-Control: no-cache

Upvotes: 2

Quentin
Quentin

Reputation: 944303

Hence the headers I set, are not useful in this scenario:

<meta http-equiv="cache-control" content="no-store" />

There problem here is that those are not headers.

They are HTML elements (which are part of the HTML document, which is the body of the HTTP response) which attempt to be equivalent to HTTP headers … and fail.

You need to set real HTTP headers, and you need to send them with the video file (rather than the HTML document).

The specifics of how you do that will depend on the HTTP server you use.

Further reading:

Upvotes: 1

Related Questions