-
Notifications
You must be signed in to change notification settings - Fork 142
Closed
Closed
Copy link
Labels
[Plugin] Speculative LoadingIssues for the Speculative Loading plugin (formerly Speculation Rules)Issues for the Speculative Loading plugin (formerly Speculation Rules)[Type] EnhancementA suggestion for improvement of an existing featureA suggestion for improvement of an existing feature
Description
Feature Description
Currently the Speculative Loading plugin provides a plsr_speculation_rules_href_exclude_paths filter to exclude URLs (and URL patterns) from being speculatively loaded. However, two situations came up recently where this was not sufficient.
- In Products added to cart in WooCommerce without clicking on Add to Cart button when Speculative Loading active #1140, WooCommerce was found to create non-idempotent add-to-cart links which add products to cart when prefetched/prerendered. WooCommerce seems to try to get around the non-idempotency by adding
rel=nofollowto the links. However, there is no way to exclude links via such an attribute without manually modifying the default rules, which was done in Exclude rel=nofollow links from prefetch/prerender #1142. (This was to avoid having to add a WooCommerce-specific URLPattern to exclude URLs with anadd-to-cartquery param, since excluding links withrel=nofollowmay be generally advisable: Should we excluderel=nofollowby default? WICG/nav-speculation#309). - In a comment on the aforementioned issue, a user wanted to customize the speculation rules so that specific URLs were opted-in for eager prerendering. That is, instead of specifying a list of URLs/URLPatterns to exclude, they wanted to provide a list of URLs/URLPatterns to include. This is not possible at present either.
To account for these two use cases, I suggest that the entire set of speculation rules (speculation ruleset?) be filterable, doing something like this:
--- a/plugins/speculation-rules/helper.php
+++ b/plugins/speculation-rules/helper.php
@@ -109,5 +109,13 @@ function plsr_get_speculation_rules() {
);
}
- return array( $mode => $rules );
+ $ruleset = array( $mode => $rules );
+
+ /**
+ * Filters the entire speculation ruleset.
+ *
+ * @param array $ruleset Ruleset.
+ * @param string $mode Mode used to apply speculative prerendering. Either 'prefetch' or 'prerender'.
+ */
+ return (array) apply_filters( 'plsr_speculation_ruleset', $ruleset, $mode );
}Also, @swissspidy suggested in #1144 (comment) that a JSON Schema could be written which could validate whatever is being returned by the filter. If not valid, it could trigger a _doing_it_wrong().
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Plugin] Speculative LoadingIssues for the Speculative Loading plugin (formerly Speculation Rules)Issues for the Speculative Loading plugin (formerly Speculation Rules)[Type] EnhancementA suggestion for improvement of an existing featureA suggestion for improvement of an existing feature
Type
Projects
Status
Done 😃