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(website): optimize blog images and fix meta/a11y #973

Merged
merged 4 commits into from
Nov 30, 2023
Merged

feat(website): optimize blog images and fix meta/a11y #973

merged 4 commits into from
Nov 30, 2023

Conversation

yanthomasdev
Copy link
Contributor

@yanthomasdev yanthomasdev commented Nov 30, 2023

Summary

This PR makes a few changes related to images:

  1. Blog post images are now part of src/content/assets so they can be processed and optimized by astro:assets, giving a big boost to page load performance, considerably increasing the page's Lighthouse score (up to 20%-30%), and also avoiding Content Layout Shift.

    Here's a table comparing the image size differences:

    Image Original Optimized
    Biome wins Prettier challenge 679kB 73.3kB
    Author GitHub Avatar 46.9kB 844B
    Ema at JSNation 1.1MB 110kB

    This means images should be referenced in a different way, in both the frontmatter and in the Markdown content - the links contain Astro Docs links with the respective code samples.

  2. Replaced a few <img> components for Astro's <Image> for optimization and to avoid CLS.

  3. Removed the duplicate public/img/blog/announcing-biome/biome-logo-slogan.png that was identical to assets/social-logo.png (same height, width, file format, content, and colors)

  4. Added the missing alt="" attribute in authors' images so that screen readers correctly ignore them.

  5. Fixed our current blog post setup where the description and social image were not being added to the page's meta tags.

Test Plan

Tested image size differences and the meta tag changes through the Dev Tools, also visually inspected to see if any images broke during migration.

@github-actions github-actions bot added the A-Website Area: website label Nov 30, 2023
const processedImage = await getImage({ src: post.socialImage });
const socialImageUrl = new URL(
processedImage.src,
Astro.site ?? "http://localhost:4321/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the right hand side be Astro.url.origin? It should be more future proof, especially if you run multiple astro dev servers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, forgot we had this property 😅 Just for context og images need to be an absolute link because of some weird limitations in how these work, so I've wrapped it into a template literal with a trailing slash.

@Conaclos
Copy link
Member

I previously used pngquant to optimize other images. Just wondering: what Astro is using under the hood to optimize images?

@yanthomasdev
Copy link
Contributor Author

I previously used pngquant to optimize other images. Just wondering: what Astro is using under the hood to optimize images?

It uses Sharp (or Squoosh if you need it). I believe it's still super valid to optimize images beforehand with something like pngquant and then let astro:assets take care of the rest.

@Conaclos Conaclos merged commit 3fab816 into biomejs:main Nov 30, 2023
4 checks passed
yossydev pushed a commit to yossydev/biome that referenced this pull request Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Website Area: website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants