WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
355 stars 97 forks source link

Preload links can be sent via `Link` HTTP response headers over HTML `link` tags #1321

Closed westonruter closed 2 months ago

westonruter commented 3 months ago

As noted in the web.dev article, Preload critical assets to improve loading speed, sending the preload links via Link HTTP response headers has a slight performance advantage over HTML link tags:

You can also preload any type of resource via the Link HTTP header:

Link: </css/style.css>; rel="preload"; as="style"

A benefit of specifying preload in the HTTP Header is that the browser doesn't need to parse the document to discover it, which can offer small improvements in some cases.

Since Optimization Detective is output-buffering the page, this can be very straightforward to implement. Instead of (or rather in addition to) doing this:

https://github.com/WordPress/performance/blob/2f2691a153cf1819a907a7cb54205d44c008bb62/plugins/optimization-detective/optimization.php#L192-L195

A new method can be added to OD_Preload_Link_Collection like send_headers() which can construct the Link response header and send it via header().

AhmarZaidi commented 3 months ago

Hey, I'd like to work on this.