Shoora
2/15/2019 - 10:07 AM

Link: https://github.com/futtta/autoptimize/issues/49#issuecomment-241138124

/**
 * [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' );