From e9f5adba7bd0938727c90cc1e12c81981c33e102 Mon Sep 17 00:00:00 2001 From: albertlast Date: Sun, 21 May 2023 08:57:04 +0200 Subject: [PATCH] Added only render YouTubeVideoEmbed in the view port add dependency svelte-inview redource the load time massiv depends of the amount video released by the channels --- package.json | 1 + src/lib/YouTubeVideoEmbed.svelte | 66 ++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 78b3ca8..f09c81e 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "env-cmd": "^10.1.0", "luxon": "^3.3.0", "redis": "^4.6.6", + "svelte-inview": "^4.0.0", "zod": "^3.21.4" }, "license": "MIT", diff --git a/src/lib/YouTubeVideoEmbed.svelte b/src/lib/YouTubeVideoEmbed.svelte index 85b0d75..b017558 100644 --- a/src/lib/YouTubeVideoEmbed.svelte +++ b/src/lib/YouTubeVideoEmbed.svelte @@ -2,41 +2,57 @@ import { page } from '$app/stores'; import { formatNumberCompact, formatDuration, formatRelativeDate } from '$lib/utils'; import ViewCount from '$lib/ViewCount.svelte'; + import { inview } from 'svelte-inview'; + import type { ObserverEventDetails, Options } from 'svelte-inview'; import type { YouTubeVideoAPIResponse } from './server/YouTubeAPI'; export let locale: string; export let active: boolean; export let video: YouTubeVideoAPIResponse; + + let isInView: boolean; + const options: Options = { + rootMargin: '50px', + unobserveOnEnter: true, + }; + + const handleChange = ({ detail }: CustomEvent) => { + isInView = detail.inView; + }; -
- {video.title} - -

- {formatNumberCompact(video.likes, locale)} 👍 -

-

- {formatDuration(video.duration)} -

-
-