From 4bdd83bd263314b1b18c2afaf7bb89047e35f4e9 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Mon, 16 Sep 2024 01:38:22 +0100 Subject: [PATCH] refactor(lib-content): reduce home and about page load times (#6255) * refactor(lib-content): use lite-youtube-embed for video embeds Use `YouTubeEmbed`, from `@next/third-parties/google`, for video embeds on the home page. This should reduce the JS download size by ~2.5MB per video. * lazy load large blog images * update the About page - use `lite-youtube-embed`. - lazy load offscreen images. * put video title in translations dictionary * fix DefaultHome padding dupe --------- Co-authored-by: Delilah <23665803+goplayoutside3@users.noreply.github.com> --- packages/lib-content/package.json | 1 + .../src/components/Article/Article.js | 20 +++++++++++++----- .../screens/About/components/Highlights.js | 3 +++ .../screens/About/components/OurMission.js | 13 ++++++------ .../screens/Home/DefaultHome/DefaultHome.js | 3 +-- .../DefaultHome/components/Introduction.js | 11 +++++----- .../DefaultHome/components/Researchers.js | 21 +++++++++---------- packages/lib-content/src/translations/en.json | 6 ++++-- yarn.lock | 12 +++++++++++ 9 files changed, 57 insertions(+), 33 deletions(-) diff --git a/packages/lib-content/package.json b/packages/lib-content/package.json index 167f19fa2d..f3fa32364b 100644 --- a/packages/lib-content/package.json +++ b/packages/lib-content/package.json @@ -30,6 +30,7 @@ "build-storybook": "storybook build" }, "dependencies": { + "@next/third-parties": "~14.2.7", "@zooniverse/async-states": "~0.0.1", "@zooniverse/react-components": "~1.13.0", "dayjs": "~1.11.11", diff --git a/packages/lib-content/src/components/Article/Article.js b/packages/lib-content/src/components/Article/Article.js index 7d87bb23f3..ca4572f31f 100644 --- a/packages/lib-content/src/components/Article/Article.js +++ b/packages/lib-content/src/components/Article/Article.js @@ -1,4 +1,4 @@ -import { Anchor, Box, Heading, Paragraph, ResponsiveContext } from 'grommet' +import { Anchor, Box, Heading, Image, Paragraph, ResponsiveContext } from 'grommet' import { string } from 'prop-types' import { useTranslation } from '../../translations/i18n.js' import styled from 'styled-components' @@ -9,6 +9,10 @@ const StyledParagraph = styled(Paragraph)` line-height: 1.2; ` +const thumbnailSize = { + max: '120px', + min: '120px' +} export default function Article({ date = '', excerpt = '', @@ -33,11 +37,17 @@ export default function Article({ {imageSrc.length && size !== 'small' ? ( + height={thumbnailSize} + width={thumbnailSize} + > + {title} + ) : null} @@ -54,6 +55,7 @@ export default function Highlights() { {t('AboutPage.highlights.pictures.two')} diff --git a/packages/lib-content/src/screens/About/components/OurMission.js b/packages/lib-content/src/screens/About/components/OurMission.js index bbc5d8dbc0..9507ea940b 100644 --- a/packages/lib-content/src/screens/About/components/OurMission.js +++ b/packages/lib-content/src/screens/About/components/OurMission.js @@ -16,6 +16,7 @@ import styled from 'styled-components' import { useContext } from 'react' import Stats from '../../../components/Stats/Stats.js' +import { YouTubeEmbed } from '@next/third-parties/google' const VideoWrapper = styled(Box)` border-radius: 8px; // same as Stat component @@ -37,7 +38,7 @@ const Discovery = ({ href, src, labelString }) => ( - + -