Skip to content

Optimize hero image #4885

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

Merged
merged 4 commits into from
Jul 28, 2022
Merged

Optimize hero image #4885

merged 4 commits into from
Jul 28, 2022

Conversation

thisisdano
Copy link
Contributor

@thisisdano thisisdano commented Jul 27, 2022

Optimize hero image. We replaced our default hero image (644 KB PNG) with an optimized image (147 KB JPG), saving 477 KB. We've also provided a next-generation image format version of the image (105 KB WEBP) as an example.

⚠️ This changes the value of $theme-hero-image. If your project uses this default hero image, you'll need to make sure to move the new asset (hero.jpg) to your project images directory.

Setting Old default New default
$theme-hero-image "#{general.$theme-image-path}/hero.png" "#{general.$theme-image-path}/hero.jpg"

Problem

Our default hero image isn't a good example of an optimized image. Even if teams don't use this generic image in their projects, we should deliver an optimized image. Additionally, we don't have a good way of distinguishing high-quality, high-resolution image originals from the optimized version (or versions) we ship. We need the uncompressed originals to make our optimized versions, but teams should not use these files in their projects.

Solution

  • Replace the current hero PNG (644 KB) with an optimized JPG (147 KB).
  • Update the value of $theme-hero-image to point to this new file ("#{general.$theme-image-path}/hero.jpg").
  • Include a WEBP version (105 KB) as an example.
  • Include the original image prefixed with an underscore and ignore underscore-prefixed files when building our dist/img directory.

How to test

  1. View the component on Federalist (Preview →)
  2. Use the inspector to see that it's using the new image (hero.jpg)
  3. Pull the branch locally and build USWDS with npx gulp
  4. Check the dist/img directory to find hero.jpg and hero.webp. You should NOT see _hero.png (the original)

Related issues

We want to keep large high-resolution images in our image source, but we want to distribute only the optimized images. Using an underscore exclusion allows us to keep the original files, but send only the optimized files to the dist
Including the webp in the dist, but using JPG as the default lets us use a highly optimized image, but also allows the user to change their settings and use the next-gen format if their site supports it
@thisisdano thisisdano requested a review from mejiaj July 27, 2022 20:51
Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

LGTM, just a question on moving processed images to dist.

@kd-usgs
Copy link

kd-usgs commented Feb 13, 2025

hero.png is still huge. This has been a problem for years. It is a stock image that users will replace. Please consider removing it from USWDS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce Hero Image Size
3 participants