Skip to content
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

Ensure only HTML responses are optimized #1189

Merged
merged 2 commits into from
May 3, 2024

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
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 <westonruter@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>

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
26 checks passed
@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.

2 participants