fix(media): cache remote image dimensions and set timeout - #1032
Open
faisalahammad wants to merge 1 commit into
Open
faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
faisalahammad
force-pushed
the
fix/1020-remote-img-dimensions-ttfb
branch
from
August 7, 2026 19:36
ff83c05 to
c002053
Compare
Adds WP transient caching and safe HTTP request handling with range headers to remote image dimension detection in _detect_dimensions(). This prevents high TTFB spikes and page hangs when fetching remote missing sizes. Fixes litespeedtech#1020
faisalahammad
force-pushed
the
fix/1020-remote-img-dimensions-ttfb
branch
from
August 7, 2026 19:53
c002053 to
2d0e060
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When "Add Missing Sizes" is enabled,
_detect_dimensions()makes synchronous HTTP requests for remote images without caching or timeouts. This change implements WordPress transient caching, range requests, and safe HTTP timeouts usingwp_safe_remote_get().Fixes #1020
Changes
src/media.cls.php
Before:
After:
Why: Remote image dimension fetches were executing un-cached serial HTTP GETs during page finalization. Caching detected dimensions in transients for 7 days (and failure states for 1 hour) with a 3-second timeout and 32KB Range header resolves TTFB delays and prevents page hangs.
Testing
Test 1: Remote image dimension caching
Result: Width and height attributes are added and subsequent page views load dimensions instantly from transient cache.
Test 2: Timeout and failure protection
Result: Request times out after 3 seconds instead of hanging, and failure status is cached for 1 hour.