Ensure only HTML responses are optimized#1189
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
74a6371 to
ae5ba8f
Compare
| 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 ); |
There was a problem hiding this comment.
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 ) ); |
There was a problem hiding this comment.
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.
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.phpgets to filteringtemplate_include.) For example, a plugin may decide to render an XML response instead for a template. These should be ignored from optimization.