Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Apr 30, 2024

I realized in WordPress/gutenberg#61212 that Optimization Detective is currently attempting to optimize all frontend responses, including those which may not be HTML. (This does not apply to feeds or robots.txt, as it only is relevant when template-loader.php gets to filtering template_include.) For example, a plugin may decide to render an XML response instead for a template. These should be ignored from optimization.

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Apr 30, 2024
@westonruter westonruter requested a review from felixarntz as a code owner April 30, 2024 00:00
@github-actions
Copy link

github-actions bot commented Apr 30, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: swissspidy <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

foreach ( $headers_list as $header ) {
$header_parts = preg_split( '/\s*[:;]\s*/', strtolower( $header ) );
if ( count( $header_parts ) >= 2 && 'content-type' === $header_parts[0] ) {
$is_html_content_type = in_array( $header_parts[1], array( 'text/html', 'application/xhtml+xml' ), true );
Copy link
Member Author

Choose a reason for hiding this comment

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

Note the application/xhtml+xml may be overkill per GoogleChromeLabs/wpp-research#74, but I added it for completeness.

headers_list()
);
foreach ( $headers_list as $header ) {
$header_parts = preg_split( '/\s*[:;]\s*/', strtolower( $header ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

Splitting on : and ; here will result in Content-Type: text/html; charset=utf-8 being split as [ 'content-type', 'text/html', 'charset=utf-8' ]. We then only use the first two items in the array.

@westonruter westonruter merged commit 99b11fc into trunk May 3, 2024
@westonruter westonruter deleted the fix/output-buffer-html-only branch May 3, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants