@@ -59,25 +59,22 @@ function perflab_bfcache_compatibility_headers_check(): array {
59
59
return $ result ;
60
60
}
61
61
62
- $ cache_control_header = wp_remote_retrieve_header ( $ response , 'cache-control ' );
63
- if ( is_string ( $ cache_control_header ) && '' === $ cache_control_header ) {
62
+ $ cache_control_headers = wp_remote_retrieve_header ( $ response , 'cache-control ' );
63
+ if ( '' === $ cache_control_headers ) {
64
64
// The Cache-Control header is not set, so it does not prevent bfcache. Return the default result.
65
65
return $ result ;
66
66
}
67
67
68
- $ cache_control_header = (array ) $ cache_control_header ;
69
- foreach ( $ cache_control_header as $ header ) {
70
- $ header = strtolower ( $ header );
71
- $ headers_to_check = array ( 'no-store ' , 'no-cache ' , 'max-age=0 ' );
72
- $ flagged_headers = array ();
73
-
74
- foreach ( $ headers_to_check as $ header_to_check ) {
75
- if ( is_int ( strpos ( $ header , $ header_to_check ) ) ) {
76
- $ flagged_headers [] = $ header_to_check ;
68
+ foreach ( (array ) $ cache_control_headers as $ cache_control_header ) {
69
+ $ cache_control_header = strtolower ( $ cache_control_header );
70
+ $ found_directives = array ();
71
+ foreach ( array ( 'no-store ' , 'no-cache ' , 'max-age=0 ' ) as $ directive ) {
72
+ if ( str_contains ( $ cache_control_header , $ directive ) ) {
73
+ $ found_directives [] = $ directive ;
77
74
}
78
75
}
79
76
80
- if ( count ( $ flagged_headers ) > 0 ) {
77
+ if ( count ( $ found_directives ) > 0 ) {
81
78
$ result ['label ' ] = __ ( 'The Cache-Control page header is preventing fast back/forward navigations ' , 'performance-lab ' );
82
79
$ result ['status ' ] = 'recommended ' ;
83
80
$ result ['description ' ] = sprintf (
@@ -88,7 +85,7 @@ function perflab_bfcache_compatibility_headers_check(): array {
88
85
_n (
89
86
'The <code>Cache-Control</code> response header for the home page includes the following directive: %s. ' ,
90
87
'The <code>Cache-Control</code> response header for the home page includes the following directives: %s. ' ,
91
- count ( $ flagged_headers ),
88
+ count ( $ found_directives ),
92
89
'performance-lab '
93
90
),
94
91
implode (
@@ -97,7 +94,7 @@ function perflab_bfcache_compatibility_headers_check(): array {
97
94
static function ( $ header ) {
98
95
return "<code> $ header</code> " ;
99
96
},
100
- $ flagged_headers
97
+ $ found_directives
101
98
)
102
99
)
103
100
),
0 commit comments