Created
December 2, 2018 20:39
-
-
Save aprakasa/2d09847d0c992ebf75765a63b385768a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [http2_server_push description] | |
* @param [type] $content [description] | |
* @return [type] [description] | |
*/ | |
function autoptimize_http2_server_push($content) { | |
$header = "Link: "; | |
if ( preg_match('#="([^"]+/js/autoptimize_[0-9a-f]+\.js)"#', $content, $matches ) ) { | |
$header .= sprintf( | |
'<%s>; rel=preload; as=%s,', | |
$matches[1], 'script' | |
); | |
} | |
if ( preg_match('#="([^"]+/css/autoptimize_[0-9a-f]+\.css)"#', $content, $matches ) ) { | |
$header .= sprintf( | |
'<%s>; rel=preload; as=%s', | |
$matches[1], 'style' | |
); | |
} | |
header( $header ); | |
return $content; | |
} | |
add_filter( 'autoptimize_html_after_minify', 'autoptimize_http2_server_push' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment