Skip to content

Commit cc1c36a

Browse files
committed
cncat link headers
1 parent 28a695b commit cc1c36a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ before_script:
3030
script:
3131
- phpunit
3232
after_success:
33-
- sed -i -e "s/nightly/${TRAVIS_TAG}/" self-hosted-wordpress-plugin-on-github.php
33+
- sed -i -e "s/nightly/${TRAVIS_TAG}/" http2-server-push.php
3434
- curl https://raw.githubusercontent.com/miya0001/auto-build/master/auto-build.sh | bash
3535
deploy:
3636
provider: releases

lib/functions.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
* @param $items array
99
*/
1010
function send_http2_link_header( $items ) {
11-
$items = apply_filters( 'http2_server_push_items', $items );
11+
$links = array();
1212
foreach( $items as $as => $urls ) {
1313
foreach ( $urls as $url ) {
14-
$link = sprintf(
14+
$links[] = sprintf(
1515
'<%s>; rel=preload; as=%s',
1616
esc_url_raw( $url ),
1717
$as
1818
);
19-
header( "Link: " . $link, false );
2019
}
2120
}
21+
22+
if ( $links ) {
23+
header( "Link: " . implode( ", ", $links ), false );
24+
}
2225
}
2326

2427
/**
@@ -27,10 +30,12 @@ function send_http2_link_header( $items ) {
2730
* @return array An array of URLs.
2831
*/
2932
function get_enqueued_items() {
30-
return array(
33+
$items = array(
3134
'style' => get_urls( wp_styles() ),
3235
'script' => get_urls( wp_scripts() ),
3336
);
37+
38+
return apply_filters( 'http2_server_push_items', $items );
3439
}
3540

3641
/**
@@ -52,7 +57,7 @@ function get_urls( $wp_links ) {
5257

5358
$urls = array();
5459
foreach ( $to_do as $handle ) {
55-
if ( ! empty( $links[ $handle ] ) && $links[ $handle ]->src ) {
60+
if ( ! empty( $links[ $handle ] ) && $links[ $handle ]->src && is_string( $links[ $handle ]->src ) ) {
5661
$src = $links[ $handle ]->src;
5762
if ( preg_match( "#^http://#", $src ) ) {
5863
continue;

0 commit comments

Comments
 (0)