Tech Tip #52: Load video only when someone presses play

Autoloaded video can outweigh the rest of the page.

Video created by explainapaper.com

The problem

Pages embed video players that fetch the video, or a heavy player script, as soon as the page opens, whether anyone watches or not.

The fix you can use today

  • Show a poster image and fetch the video only on click.
  • Use preload="none" on video elements.
  • Swap a lightweight placeholder for third-party players until they are used.

GreenCode's own website loads its films only when someone presses play.

Tools that help

  • Lighthouse: audits a page for total byte weight, unused JavaScript and CSS, image formats and offscreen images
  • WebPageTest: loads a real page and shows every request, its size and when it loaded

How GreenCode helps

GreenCode helps tackle this by practising it on greencode.ai: films load only when someone presses play, and static pages, WebP images and scripts only where they are used cut the home page's first view from 6,766 KB to 1,719 KB. More on this.

Tags

#video#web-performance#frontend

Sources

All GreenCode Tech Tips

  • Tip #52
  • For Developers
  • Category Web and front-end
  • Format short video
GreenCode

Want this checked on your own system? Talk to the GreenCode team.

Get in touch