Functions – homepage gif animation loading adaptation

I put a GIF animation at the start of my website that has a fading transition to the actual website and with different WiFi speeds, the point at which the video goes until the fading is different.
Now I will not explain how I implemented the video because that will take too much time.
So, the real question is how would a gif be placed at the start of the website that would adapt to the WiFi speed, without loops, do not fade prematurely.
Any ideas?