Speculative Loading

Mô tả

This plugin adds support for the Speculation Rules API, which allows defining rules by which certain URLs are dynamically prefetched or prerendered.

Xem bản dự thảo đặc tả Quy tắc Dự đoán WICG.

By default, the plugin is configured to prerender WordPress frontend URLs when the user interacts with a relevant link. This can be customized via the “Speculative Loading” section in the Settings > Reading admin screen.

A filter can be used to exclude certain URL paths from being eligible for prefetching and prerendering (see FAQ section). Alternatively, you can add the no-prerender CSS class to any link (<a> tag) that should not be prerendered. See FAQ for more information.

Hỗ trợ trình duyệt

The Speculation Rules API is a new web API, and the functionality used by the plugin is supported in Chromium-based browsers such as Chrome, Edge, or Opera using version 121 or above. Other browsers such as Safari and Firefox will ignore the functionality with no ill effects; they will simply not benefit from the speculative loading. Note that certain browser extensions may disable preloading by default.

Plugin này trước đây được gọi là Quy tắc Dự đoán.

Cài đặt

Cài đặt từ trong WordPress

  1. Hãy truy cập Plugin > Thêm mới.
  2. Tìm kiếm Tải Dự Đoán.
  3. Cài đặt và kích hoạt plugin Speculative Loading.

Cài đặt thủ công

  1. Tải lên toàn bộ thư mục speculation-rules vào thư mục /wp-content/plugins/.
  2. Truy cập Plugin.
  3. Kích hoạt plugin Speculative Loading.

Hỏi đáp

Làm cách nào để ngăn một số URL nhất định được tải trước và hiển thị trước?

Not every URL can be reasonably prerendered. Prerendering static content is typically reliable, however prerendering interactive content, such as a logout URL, can lead to issues. For this reason, certain WordPress core URLs such as /wp-login.php and /wp-admin/* are excluded from prefetching and prerendering. Additionally, any URLs generated with wp_nonce_url() (or which contains the _wpnonce query var) and nofollow links are also ignored. You can exclude additional URL patterns by using the plsr_speculation_rules_href_exclude_paths filter.

The following example ensures that URLs like https://example.com/cart/ or https://example.com/cart/foo are excluded from prefetching and prerendering:

<?php
add_filter(
    'plsr_speculation_rules_href_exclude_paths',
    function ( array $exclude_paths ): array {
        $exclude_paths[] = '/cart/*';
        return $exclude_paths;
    }
);

Hãy nhớ rằng đôi khi, việc loại trừ URL khỏi hiển thị trước trong khi vẫn cho phép tải trước có thể hữu ích. Ví dụ: một trang có JavaScript phía máy khách để cập nhật trạng thái người dùng có thể không nên được hiển thị trước, nhưng sẽ hợp lý nếu tải trước.

Với mục đích này, bộ lọc plsr_speculation_rules_href_exclude_paths nhận chế độ hiện tại (hoặc “prefetch” hoặc “prerender”) để cung cấp các ngoại lệ có điều kiện.

The following example ensures that URLs like https://example.com/products/... cannot be prerendered, while still allowing them to be prefetched:

<?php
add_filter(
    'plsr_speculation_rules_href_exclude_paths',
    function ( array $exclude_paths, string $mode ): array {
        if ( 'prerender' === $mode ) {
            $exclude_paths[] = '/products/*';
        }
        return $exclude_paths;
    },
    10,
    2
);

Như đã đề cập ở trên, việc thêm lớp CSS no-prerender vào một liên kết sẽ ngăn liên kết đó hiển thị trước (nhưng không tải trước). Ngoài ra, các liên kết có rel=nofollow sẽ không được tải trước hoặc hiển thị trước vì một số plugin thêm điều này vào các liên kết không phải idempotent (ví dụ: thêm vào giỏ hàng); các liên kết như vậy lý tưởng nên là các nút kích hoạt yêu cầu POST hoặc ít nhất chúng nên sử dụng wp_nonce_url().

Điều này sẽ ảnh hưởng như thế nào đến phân tích và cá nhân hóa?

Việc hiển thị trước có thể ảnh hưởng đến phân tích và cá nhân hóa.

For client-side JavaScript, is recommended to delay these until the prerender is activated (for example by clicking on the link). Some solutions (like Google Analytics) already do this automatically, see Impact on Analytics. Additionally, cross-origin iframes are not loaded until activation which can further avoid issues here.

Speculating with the default moderate eagerness decreases the risk that the prerendered page will not be visited by the user and therefore will avoid any side effects of loading such a link in advance. In contrast, eager speculation increases the risk that prerendered pages may not be loaded. Alternatively, the plugin offers to only speculate on mouse/pointer down (conservative) which reduces the risk even further and is an option for sites which are concerned about this, at the cost of having less of a lead time and so less of a performance gain.

A prerendered page is linked to the page that prerenders it, so personalisation may already be known by this point and changes (e.g. browsing other products, or logging in/out) often require a new page load, and hence a new prerender, which will then take these into account. But it definitely is something to be aware of and test! Prerendered pages can be canceled by removing the speculation rules <script> element from the page using standard JavaScript DOM APIs should this be needed when state changes without a new page load.

Tôi có thể gửi phản hồi về plugin của mình ở đâu?

Phản hồi được khuyến khích và rất được hoan nghênh, đặc biệt là vì plugin này có thể chứa các tính năng cốt lõi của WordPress trong tương lai. Nếu bạn có đề xuất hoặc yêu cầu về các tính năng mới, bạn có thể gửi chúng dưới dạng sự cố trong kho lưu trữ GitHub của Nhóm Hiệu suất WordPress. Nếu bạn cần trợ giúp khắc phục sự cố hoặc có câu hỏi về plugin, vui lòng tạo một chủ đề mới trên diễn đàn hỗ trợ của chúng tôi.

Tôi có thể báo lỗi bảo mật ở đâu?

Nhóm Hiệu suất và cộng đồng WordPress rất coi trọng các lỗi bảo mật. Chúng tôi đánh giá cao nỗ lực của bạn trong việc tiết lộ một cách có trách nhiệm những phát hiện của mình và sẽ nỗ lực hết sức để ghi nhận những đóng góp của bạn.

Để báo lỗi bảo mật, vui lòng truy cập chương trình WordPress HackerOne.

Tôi có thể đóng góp cho plugin như thế nào?

Chúng tôi luôn hoan nghênh mọi sự đóng góp! Tìm hiểu thêm về cách tham gia trong Sổ tay nhóm Hiệu suất cốt lõi.

Đánh giá

19 Tháng bảy, 2024 1 trả lời
I was using another plugin which does a similar job but Speculative Loading appears to be substantially quicker. Using on about 10 sites and no issues. Thank you
27 Tháng năm, 2024
Es verkürzt die Ladzeit für einen Benutzer sichtbar, auch wenn im Hintergrund die Seite gleichschnell geladen wird, so fühlt es sich für einen Benutzer extrem schnell an.
8 Tháng năm, 2024 1 trả lời
I’ve currently activated this plugin on five sites, some on one server, and then others on another. The plugin has yet to present any plugin conflicts or other issues. The time to load pages is drastically improved based on user intent, and based on this alone, I cannot recommend this plugin enough. I haven’t tested the sites with Lighthouse, but honestly, I don’t feel the need to do that, because it’s about the user experience first, and that is such an improvement with this plugin. Thank you!
Đọc tất cả 16 đánh giá

Người đóng góp & Lập trình viên

“Speculative Loading” là mã nguồn mở. Những người sau đã đóng góp vào plugin này.

Những người đóng góp

“Speculative Loading” đã được dịch qua 8 ngôn ngữ. Cảm ơn những người tham gia dịch vì đóng góp của họ.

Dịch “Speculative Loading” sang ngôn ngữ của bạn.

Muốn tham gia phát triển?

Duyệt code, check out SVN repository, hoặc theo dõi nhật ký phát triển qua RSS.

Nhật ký thay đổi

1.3.1

Sửa lỗi

  • Kiểm tra xem rel có chứa nofollow hay không thay vì chỉ là nofollow khi loại trừ tải dự đoán. (1232)

1.3.0

Cải tiến

  • Ngăn tải dự đoán các liên kết đến thư mục tải lên, nội dung, plugin, mẫu hoặc bảng định kiểu. (1167)
  • Tạo điều kiện nhúng Tải Dự đoán trong các plugin/chủ đề khác. (1159)
  • Cải thiện chất lượng mã tổng thể với các kiểm tra phân tích tĩnh nghiêm ngặt hơn. (775)
  • Tăng yêu cầu PHP tối thiểu lên 7.2. (1130)

1.2.2

Sửa lỗi

  • Sửa lỗi thành phần của các đường dẫn loại trừ href để tính đến mã hóa JSON và các URL trang web/trang chủ khác nhau. (1164)

Tài liệu

  • Cập nhật tệp readme với hỗ trợ trình duyệt và phần Câu hỏi thường gặp về phân tích và cá nhân hóa. (1155)

1.2.1

Cải tiến

  • Thêm liên kết cài đặt vào liên kết hành động của plugin Speculative Loading. (1145)
  • Tăng phiên bản PHP tối thiểu lên 7.2. (1130)

Sửa lỗi

  • Loại trừ các URL _wpnonce trong quy tắc dự đoán. (1143)
  • Loại trừ các liên kết rel=nofollow khỏi tải trước/hiển thị trước. (1142)

1.2.0

  • Thêm uninstall.php bị thiếu để xóa tùy chọn cơ sở dữ liệu của plugin. (1128)

1.1.0

  • Cho phép loại trừ cụ thể các mẫu URL khỏi hiển thị trước hoặc tải trước. (1025)
  • Đổi tên plugin thành “Speculative Loading”. (1101)
  • Thêm thẻ trình tạo Tải Dự đoán. (1102)
  • Tăng phiên bản WP tối thiểu bắt buộc lên 6.4. (1062)
  • Cập nhật phiên bản WordPress đã thử nghiệm lên 6.5. (1027)

1.0.1

  • Thoát tiền tố đường dẫn và hạn chế nó là tên đường dẫn trong Quy tắc Dự đoán. (951)
  • Buộc hỗ trợ chủ đề tập lệnh HTML5 khi in tập lệnh JSON. (952)
  • Thêm biểu tượng và biểu ngữ cho thư mục plugin. (987)

1.0.0

  • Phát hành ban đầu của plugin Speculative Loading như một plugin độc lập. (733)