jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Please add a filter hook on wp-cache-phase1.php that takes in the file name

Open trajano opened this issue 9 years ago • 3 comments

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" );

trajano avatar Aug 21 '16 19:08 trajano

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

trajano avatar Aug 21 '16 19:08 trajano

Not sure if this'll help, but Automattic/wp-super-cache#121 adds a bunch of filters.

iandunn avatar Aug 22 '16 15:08 iandunn

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.

donnchawp avatar Jul 23 '18 11:07 donnchawp