-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
686f544
commit a94eedf
Showing
11 changed files
with
228 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Video | ||
jampack: "--onlyoptim" | ||
--- | ||
|
||
`jampack` optimize videos below [the fold](/features/optimize-above-the-fold/). | ||
|
||
## Autoplay videos | ||
|
||
Videos below the fold with attribute `autoplay` are lazy loaded using JavaScript. | ||
|
||
## Click-to-play videos | ||
|
||
Videos without `autoplay` and with a `poster` get a `preload="none"` attribute to postpone the loading of the video until user request. | ||
|
||
As of today, `jampack` doesn't automatically create posters for video. It's a TODO. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<h1>Lazy load videos below the fold</h1> | ||
<video | ||
src="https://cdn.divriots.com/f2w/motion1-v1.mp4" | ||
autoplay="" | ||
muted="" | ||
loop="" | ||
playsinline="" | ||
webkit-playsinline="" | ||
></video> | ||
<the-fold></the-fold> | ||
<div>The fold</div> | ||
<video | ||
src="https://cdn.divriots.com/f2w/motion3-v1.mp4" | ||
autoplay="" | ||
muted="" | ||
loop="" | ||
playsinline="" | ||
webkit-playsinline="" | ||
></video> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as cheerio from '@divriots/cheerio'; | ||
import type { GlobalState } from '../state.js'; | ||
import { install_lozad } from '../utils/install-dep.js'; | ||
|
||
export async function processVideo( | ||
state: GlobalState, | ||
htmlfile: string, | ||
video: cheerio.Cheerio<cheerio.Element>, | ||
isAboveTheFold: boolean, | ||
appendToBody: Record<string, string> | ||
): Promise<void> { | ||
const autoplay = video.attr('autoplay'); | ||
if (!autoplay || autoplay === '0' || autoplay === 'false') { | ||
// If the video is not autoplay we can postpone loading | ||
// if there is a poster | ||
if (video.attr('poster')) { | ||
video.attr('preload', 'none'); | ||
return; | ||
} | ||
|
||
// TODO create poster for videos without poster | ||
} | ||
|
||
const lazyloadOptions = state.options.video.autoplay_lazyload; | ||
if (lazyloadOptions.when === 'never') { | ||
return; | ||
} | ||
|
||
if ( | ||
lazyloadOptions.when === 'always' || | ||
(lazyloadOptions.when === 'below-the-fold' && !isAboveTheFold) | ||
) { | ||
if (lazyloadOptions.how === 'js') { | ||
video.attr('class', 'jampack-lozad'); | ||
const src = video.attr('src'); | ||
if (src) { | ||
video.attr('data-src', src); | ||
video.removeAttr('src'); | ||
} | ||
await install_lozad(state, htmlfile, appendToBody); | ||
} | ||
} | ||
} |
Oops, something went wrong.