准备就绪时延迟加载或淡入视频 - 旨在提高 FCP

问题描述 投票:0回答:1

我的登陆页面使用全屏 (110vh/vw) 视频背景,该背景位于网站上所有内容的后面。这一切都按预期工作,但如果可能的话,我想在运行灯塔测试时提高First Contentful Paint的性能。

显然,大视频背景永远不会是理想的,而且综合考虑,分数也不会太差。但就上下文而言,目标是成为一个有影响力的登陆页面。

但这让我开始思考,封面图像显示是否可以提高性能/分数。然后视频在准备好时加载/显示,还是在 FCP 之后一秒钟加载/显示?

视频确实需要自动播放,因此排除了

preload="none"

处理这个问题的最佳方法是什么?我是否遗漏了一些东西,或者它需要是 Javascript 吗?

html {
  background: black;
}

html,
body {
  box-sizing: border-box;
  color: white;
  min-height: 100vh;
  margin: 0;
  padding: 32px;
  width: 100%;
}

.video-bg {
  height: 100vh;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  z-index: -1;
}

.video-bg video {
  height: 100vh;
  object-fit: cover;
  opacity: .48;
  width: 100vw;
}

.main {
  margin: 0 auto;
  max-width: 1200px;
}
<div class="video-bg">
  <video autoplay loop muted playsinline poster="video/video-bg-poster.avif">
    <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" width="1920" height="1080">
  </video>
</div>

<div class="main">
  <h2>Page Content</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
  <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
    sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
  <p>Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem
    ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
</div>

javascript html video lazy-loading lighthouse
1个回答
0
投票

尝试使用 Intersection Observer API 在后台加载视频。在视频加载之前可以使用图像占位符。

这篇文章作为起点可能会有所帮助:https://imagekit.io/blog/lazy-loading-html-videos/

© www.soinside.com 2019 - 2024. All rights reserved.