內容簡介
HTTP/2 是驅動網頁的傳統 HTTP 協定的新一代。其最強大的功能之一是伺服器推送,一種讓網頁伺服器在瀏覽器需要資源之前就將它們發送到瀏覽器的方式。這避免了網頁上每個腳本或樣式表都要進行 HTTP 請求/回應循環的情況。
此外掛程式使 WordPress 能夠在將每個佇列腳本和樣式表輸出到頁面源代碼時,為其發送 Link:<...> rel="prefetch" 標頭。不幸的是,它無法幫助直接輸出其腳本的外掛程式和主題,但這些將繼續按照它們一直這樣運作。
需要支援 HTTP/2 的網頁伺服器。
WordPress 4.6及以上版本
WordPress 4.6引入了對資源提示的本機支援。
默認情況下,此外掛程式會服從 WordPress 4.6 和主題 / 外掛程式開發者的要求,負責預取正確的資產。運行在
較舊版本的 WordPress 上的網站將繼續獲得以前的行為,其中會為所有 JavaScript 和樣式表打印資源提示。
我已經添加了一個篩選器,以恢復 WordPress 4.6及以上版本的舊行為(提示所有內容)。要使用它,請在以下位置的
主題 functions.php 文件或自定義外掛程式中添加此行:
`add_filter('http2_render_resource_hints', '__return_true');```
外掛標籤
開發者團隊
原文外掛簡介
HTTP/2 is the new generation of the venerable HTTP protocol that powers the web. Among its most powerful features is server push, a way for web servers to send resources to the browser before it even realizes it needs them. This avoids the usual HTTP request/response cycle which happened for every script or stylesheet on a page.
This plugin enables WordPress to send a Link:<...> rel="prefetch" header for every enqueued script and style as WordPress outputs them into the page source. Unfortunately, it can’t help plugins and themes that output their scripts directly into the page itself, but these will continue to work as they always have.
Requires a web server that supports HTTP/2.
WordPress 4.6 and above
WordPress 4.6 introduced native support for resource hints.
By default, this plugin defers to WordPress 4.6 and theme/plugin developers to responsibly prefetch the right assets. Sites running
on older versions of WordPress will continue to get the previous behavior where all JavaScript and stylesheets had resource hints
printed for them.
I’ve added a filter To restore the old behavior (hint everything) on WordPress 4.6 and above. To use it, add this line to
your theme’s functions.php file or a custom plugin:
`add_filter('http2_render_resource_hints', '__return_true');```
