Skip to content

Instantly share code, notes, and snippets.

@aprakasa
Created December 2, 2018 20:39
Show Gist options
  • Save aprakasa/2d09847d0c992ebf75765a63b385768a to your computer and use it in GitHub Desktop.
Save aprakasa/2d09847d0c992ebf75765a63b385768a to your computer and use it in GitHub Desktop.
/**
* [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