Skip to content

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

@westonruter

Description

@westonruter

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:

// Inject any preload links at the end of the HEAD.
if ( count( $preload_links ) > 0 ) {
$walker->append_head_html( $preload_links->get_html() );
}

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().

Metadata

Metadata

Assignees

Labels

Good First IssueIssue particularly suitable to be worked on by new contributors[Plugin] Optimization DetectiveIssues for the Optimization Detective plugin[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type
No fields configured for issues without a type.

Projects

Status

Done 😃

Relationships

None yet

Development

No branches or pull requests

Issue actions