Skip to content

Don't flag images served modern via Accept negotiation - #180

Open
M-arcus wants to merge 2 commits into
sitespeedio:mainfrom
M-arcus:modern-image-serving-via-accept-header
Open

M-arcus wants to merge 2 commits into
sitespeedio:mainfrom
M-arcus:modern-image-serving-via-accept-header

Conversation

@M-arcus

@M-arcus M-arcus commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request refactors how the tool checks for modern image formats (like AVIF and WebP) to more accurately detect what image formats are actually served to users. The main logic for detecting modern image formats has been moved from the DOM-based script to a new HAR-based rule, which inspects the actual Content-Type headers in HTTP responses. This approach avoids false positives/negatives caused by relying on file extensions or DOM heuristics, and allows for correct handling of Accept-based content negotiation. The update also introduces comprehensive tests for the new logic and adds support for new image MIME types in the test webserver.

Modern image format detection overhaul:

  • Replaces the DOM-based rule in lib/dom/performance/modernImageFormats.js with a new HAR-based rule in lib/har/performance/modernImageFormats.js that checks the actual Content-Type delivered, ensuring accurate identification of legacy and modern image formats regardless of URL or markup. [1] [2]

Utility enhancements:

  • Adds a new util.getResourceContentType function in lib/dom/util.js to allow in-page scripts to retrieve the real Content-Type of resources using the PerformanceResourceTiming API, although this is now less central due to the HAR-based approach.

Test improvements:

  • Introduces an extensive test suite for the new HAR-based modern image formats rule in test/har/performance/modernImageFormatsTest.js, covering various scenarios including content negotiation, content-type casing/parameters, partial legacy/modern mixes, missing content-types, and exclusion of tracking pixels.
  • Updates the test webserver in test/help/webserver.js to serve .webp and .avif files with correct MIME types, and makes a minor refactor to directory handling logic. [1] [2]

Test cleanup:

  • Removes a now-unnecessary blank line from a DOM performance test.

@M-arcus
M-arcus marked this pull request as draft September 8, 2026 10:34
@M-arcus
M-arcus marked this pull request as ready for review September 8, 2026 11:42
@M-arcus
M-arcus force-pushed the modern-image-serving-via-accept-header branch from f3b5b1c to 1674da6 Compare September 8, 2026 11:47
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.

1 participant