Toggle NextJS image optimization with an env var #2385
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
OPTIMIZE_IMAGES=true
. Inspect any image on the homepage. Its src should start with_next/
, likehttp://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 theurl=https...
part is the raw image urlOPTIMIZE_IMAGES=false
(or anything else other thantrue
). Image sources should have be raw image url.sAdditional 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