Looking to implement a 16:9 video under the navigation and above the fold in my index.js but I'm trying to figure out how to preload the video before rendering the page. In my research I've read Working with Video that shows how to implement with an iframe:
import React from "react"
const Video = ({ videoSrcURL, videoTitle, ...props }) => (
<div className="video">
<iframe
src={videoSrcURL}
title={videoTitle}
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
frameBorder="0"
webkitallowfullscreen="true"
mozallowfullscreen="true"
allowFullScreen
/>
</div>
)
export default Video
It's mentioned for best results to use a CDN and there is a Vimeo plugin gatsby-source-vimeo-all:
import React from 'react'
import { graphql, useStaticQuery } from 'gatsby'
const query = graphql`
{
vimeo(link: { eq: "https://vimeo.com/315401283/dfd80bf8c1" }) {
name
description
duration
link
aspectRatio
width
height
srcset {
...GatsbyVimeoSrcSet
}
pictures {
uri
}
user {
name
}
}
}
`
const Video = () => {
const { vimeo } = useStaticQuery(query)
return <video src={vimeo.srcset[0].link} controls autoPlay loop />
}
export default Video
I'm already eliminating the video for smaller devices with a React component that detects browser size. My thinking is to use gatsby-browser.js to implement with accessing the location data location.pathname
but I'm not finding any docs on how this should be done. When I research for preloading video I've read:
- Force a full preload HTML5 video with Javascript?
- How to preload video
- Video preloading: must have a valid
as
value in Chrome
Gatsby research:
- Load third party iframe in React after page load, so that the iframe does not affect PageSpeed score
- (Gatsby) Datawrapper iframes aren't displaying before I've refreshed the page
- Embedding a video with Gatsby
In Gatsby how should a video be handled for the index.js located above the fold or is there a way in Gatsby to detect when the iframe is loaded so I could use a conditional render?