Skip to content

Commit 41f9b49

Browse files
swissspidywestonruteradamsilversteintunetheweb
authored
Merge pull request #1142 from WordPress/fix/woocommerce-add-to-cart-preloading
Exclude rel=nofollow links from prefetch/prerender Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org> Co-authored-by: tunetheweb <tunetheweb@git.wordpress.org> Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
2 parents dbc763f + 7d46229 commit 41f9b49

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎plugins/speculation-rules/helper.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function plsr_get_speculation_rules() {
7777
'source' => 'document',
7878
'where' => array(
7979
'and' => array(
80-
// Prerender any URLs within the same site.
80+
// Include any URLs within the same site.
8181
array(
8282
'href_matches' => $prefixer->prefix_path_pattern( '/*' ),
8383
),
@@ -87,6 +87,12 @@ function plsr_get_speculation_rules() {
8787
'href_matches' => $href_exclude_paths,
8888
),
8989
),
90+
// Also exclude rel=nofollow links, as plugins like WooCommerce use that on their add-to-cart links.
91+
array(
92+
'not' => array(
93+
'selector_matches' => 'a[rel=nofollow]',
94+
),
95+
),
9096
),
9197
),
9298
'eagerness' => $eagerness,

‎tests/plugins/speculation-rules/speculation-rules-helper-test.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function test_plsr_get_speculation_rules_prerender() {
100100
$rules = plsr_get_speculation_rules();
101101

102102
$this->assertArrayHasKey( 'prerender', $rules );
103-
$this->assertCount( 3, $rules['prerender'][0]['where']['and'] );
103+
$this->assertCount( 4, $rules['prerender'][0]['where']['and'] );
104104
}
105105

106106
/**
@@ -112,7 +112,7 @@ public function test_plsr_get_speculation_rules_prefetch() {
112112
$rules = plsr_get_speculation_rules();
113113

114114
$this->assertArrayHasKey( 'prefetch', $rules );
115-
$this->assertCount( 2, $rules['prefetch'][0]['where']['and'] );
115+
$this->assertCount( 3, $rules['prefetch'][0]['where']['and'] );
116116
}
117117

118118
/**

0 commit comments

Comments
 (0)