Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lazy-load external images + ability to customize image display #6990

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

slorber
Copy link
Collaborator

@slorber slorber commented Mar 24, 2022

Motivation

Fix #6965

Apply MDX image default lazy-loading from MDXImg component instead of the Remark transform

cc @johnnyreilly

This makes it possible for the user to more easily change the lazy-loading config on a case-by-case basis thanks to swizzling

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview works and lazy-load images

Related PRs

Revert #6598

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Mar 24, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 24, 2022
@netlify
Copy link

netlify bot commented Mar 24, 2022

[V2]

Name Link
🔨 Latest commit c1f5e38
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/623cb889eaa9440009e13426
😎 Deploy Preview https://deploy-preview-6990--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 53
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6990--docusaurus-2.netlify.app/

@github-actions
Copy link

Size Change: 0 B

Total Size: 805 kB

ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/assets/css/styles.********.css 105 kB
website/build/assets/js/main.********.js 612 kB
website/build/index.html 38.3 kB

compressed-size-action

@johnnyreilly
Copy link
Contributor

I might be reading this wrong, but the snapshots seem to suggest that this removed lazy loading? Am I misunderstanding?

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Mar 24, 2022

This has moved the addition of loading="lazy" from the Remark plugin to the MDXComponents provider which kicks in when the loaded MDX is being rendered. The final markup still contains loading="lazy":

image

IMO this is better, because it also means the user can easily opt-out of lazy loading through swizzling.

@Josh-Cena Josh-Cena changed the title feat: apply Markdown image lazy-loading to external images too + provide more flexibility feat: lazy-load external images + ability to customize image display Mar 25, 2022
@johnnyreilly
Copy link
Contributor

Okay cool!

@slorber slorber merged commit dc95cb8 into main Mar 25, 2022
@slorber slorber deleted the slorber/mdx-img-lazy-loading branch March 25, 2022 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazy load external images
4 participants