jetpack
jetpack copied to clipboard
Please add a filter hook on wp-cache-phase1.php that takes in the file name
I would like to add something that changes the header based on the contents of the original file namely to put preloads in the header. For example for https://github.com/futtta/autoptimize/issues/49#issuecomment-241273162
$uncompressed_file_data = file_get_contents( $file );
$header = "Link: ";
if (preg_match('#="([^"]+/js/autoptimize_[0-9a-f]+\.js)"#', $uncompressed_file_data, $matches)) {
$header .= sprintf('<%s>; rel=preload; as=%s,', $matches[1], 'script');
}
if (preg_match('#="([^"]+/css/autoptimize_[0-9a-f]+\.css)"#', $uncompressed_file_data, $matches)) {
$header .= sprintf('<%s>; rel=preload; as=%s', $matches[1], 'style');
}
header($header);
just before
header( "Vary: Accept-Encoding, Cookie" );
Another way it can be improved is to use the existing wp_cache_ob_callback_filter to do the extra analysis and write to a file in the cache say:
$file.headers
Where if found it will read it for additional headers as part of the filter in wp-cache-phase1.php
Not sure if this'll help, but Automattic/wp-super-cache#121 adds a bunch of filters.
There's a "Cache HTTP headers with page content" setting now that you could use to add the headers when serving the page initially. The headers you want will be cached with the page then.