Skip to content

Commit

Permalink
Boost: Prioritize cornerstone provider while serving critical CSS (#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
haqadn authored Nov 4, 2024
1 parent 931e59a commit 72cd1b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class Source_Providers {
* @var Provider[]
*/
protected $providers = array(
Cornerstone_Provider::class,
Post_ID_Provider::class,
WP_Core_Provider::class,
Singular_Post_Provider::class,
Archive_Provider::class,
Taxonomy_Provider::class,
Cornerstone_Provider::class,
);

public function get_providers() {
Expand Down Expand Up @@ -110,6 +110,10 @@ public function get_current_request_css() {
return $this->request_cached_css;
}

public function get_current_critical_css_key() {
return $this->current_critical_css_key;
}

/**
* Get providers sources.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public static function get_keys() {
* @inheritdoc
*/
public static function get_hash_for_url( $url ) {
// Remove the home_url from the beginning of the URL.
$home_url = home_url();
if ( stripos( $url, $home_url ) === 0 ) {
$url = substr( $url, strlen( $home_url ) );
}

$hash = hash( 'md5', $url );

return substr( $hash, 0, 8 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function display_critical_css() {
return;
}

if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
$critical_css = "/* Critical CSS Key: {$this->paths->get_current_critical_css_key()} */\n" . $critical_css;
}

$display = new Display_Critical_CSS( $critical_css );
add_action( 'wp_head', array( $display, 'display_critical_css' ), 0 );
add_filter( 'style_loader_tag', array( $display, 'asynchronize_stylesheets' ), 10, 4 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function display_critical_css() {
return;
}

if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
$critical_css = "/* Critical CSS Key: {$this->paths->get_current_critical_css_key()} */\n" . $critical_css;
}

$display = new Display_Critical_CSS( $critical_css );
add_action( 'wp_head', array( $display, 'display_critical_css' ), 0 );
add_filter( 'style_loader_tag', array( $display, 'asynchronize_stylesheets' ), 10, 4 );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Change to an unreleased feature


0 comments on commit 72cd1b2

Please sign in to comment.