0

I'm having a trouble with a video that is located in my web apache server.

This video I'm loading it on the index php page, but the problem is that it take too many time to load the video and start to reproduce.

Well, there's any way to load this video in a server cache, so that don't take too many time in load the video?

This is the code that loads the video into my html page:

<video id="mivideo" autoplay="autoplay" muted loop>
    <source src="../video/video.mp4" type="video/mp4"></source>
</video>

Note; When I refresh the website in the same computer, for a couple of hours the video don't take too many time, because the web browser loads it into the cookies or local cache, but if I go to another computer, the video take long time to load, again...

Really thanks!

ajzbrun
  • 113
  • 1
  • 12
  • Please, provide some code of how you are loading the video. – David Rojo Apr 27 '18 at 17:13
  • @DavidRojo Okay! there is the code :) Thanks – ajzbrun Apr 27 '18 at 17:20
  • This seems like a browser cache issue. Do you encounter your problem when refreshing your page with `Ctrl+F5` ? Why do you think that this is a server caching problem ? Is the video remote or on your server ? – Thomas P. Apr 27 '18 at 17:22
  • @ThomasP. No no, I don't saying that is a server caching problem, the problem is that I don't know how to cache the video in the server... The video is in my server – ajzbrun Apr 27 '18 at 17:26
  • Right, so you want to tell the browser to keep in cache the video. Would the `Cache-Control` header do the job ? https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control – Thomas P. Apr 27 '18 at 17:27
  • @ThomasP. First, thanks for your help haha. Then, hmmm no, I don't wanna tell the browser that, I want that the server keept the video on his cache, so that any user on any computer that access the web site have inmediatly load of the video... I'm explain my self? – ajzbrun Apr 27 '18 at 17:30
  • As far as I can see, php is not involved in the video download, the video should be loaded by nginx or apache or the webserver you are using, so it seems to be an issue with the server performance. Could you provide an url to check it? – David Rojo Apr 27 '18 at 17:33

1 Answers1

2

Server caching refers to caching remote resources on your server to prevent your server from having to download this resource everytime. Since the video is already stored on your server, and not on a remote host, there is no need for server caching here.

What you're trying to achieve here is prevent the browser from fetching the video again (which, according to you, takes a long time). This can be achieved through the Cache-Control header. See this question (especially the .htaccess part) for hints on how to set it with your webserver.

As a side note, if you want to make the loading of the video faster when it is not yet present on the client browser (or the cache was cleaned), you should re-encode it with a lower quality. This can be achieved with ffmpeg for example. Be careful to use an appropriate encoding to make sure your video can be played across all browsers. H.264 seems to be the only codec supported by all major browsers.

Thomas P.
  • 463
  • 4
  • 12