dgp1130 / blog

Source repository for my personal blog.
https://blog.dwac.dev
3 stars 2 forks source link

Lazy load videos #56

Closed dgp1130 closed 4 months ago

dgp1130 commented 1 year ago

Videos should be loaded only once they are in or near the viewport. Unfortunately videos seem to load eagerly by default. This post talks about the details, but it seems there is no way to make a <video /> element lazy load while autoplaying when visible. My attempt at hacking a workaround failed.

I think the right solution here is to create a <dwac-video /> element which includes a <noscript><video /></noscript> to be compatible when JS is disabled. When JS is enabled, the component should client-side render a <video /> tag using a lazy-loading strategy. It's a lot more effort than it should be for something like this, but probably worth the investment given the way I've been using demo videos lately.

dgp1130 commented 4 months ago

Fixed in https://github.com/dgp1130/blog/commit/cd59a6835da4331107fcb012a4c9a3feee4be664.