Skip to content

Toggle NextJS image optimization with an env var #2385

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ChristopherChudzicki
Copy link
Contributor

@ChristopherChudzicki ChristopherChudzicki commented Jul 22, 2025

What are the relevant tickets?

None

Description (What does it do?)

This adds an env variable to toggle NextJS's image optimization

This PR was made during a production incident when images were returning 502. It turned out to be sporadic 502s not limited to images, but we made this PR to disable image optimization.

Being able to toggle image optimization via an env var seems potentially useful, so making the PR.

How can this be tested?

  1. Run locally with OPTIMIZE_IMAGES=true. Inspect any image on the homepage. Its src should start with _next/, like http://learn.odl.local:8062/_next/image?url=https%3A%2F%2Fprofessional.mit.edu%2Fsites%2Fdefault%2Ffiles%2F2025-01%2FMPE-LNO-ENG-Course_Header-400x400.png&w=640&q=75; note the url=https... part is the raw image url
  2. Run locally with OPTIMIZE_IMAGES=false (or anything else other than true). Image sources should have be raw image url.s

Additional Context

We had some trouble on prod this morning. Turned out not to be due to image optimization.

Still might be useful to have a flag to enable/disable image optimization, so making the PR.

Merge Checklist

@ChristopherChudzicki ChristopherChudzicki changed the title Cc/turn off image optimization Toggle NextJS image optimization with an env var Jul 22, 2025
@shanbady shanbady self-requested a review July 23, 2025 16:57
Copy link
Contributor

@shanbady shanbady left a comment

Choose a reason for hiding this comment

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

👍 LGTM

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

Successfully merging this pull request may close these issues.

2 participants