Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
westonruter opened this issue Jun 25, 2024 · 1 comment · Fixed by #1323
Closed

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

westonruter opened this issue Jun 25, 2024 · 1 comment · Fixed by #1323
Assignees
Labels
Good First Issue Issue particularly suitable to be worked on by new contributors [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@westonruter
Copy link
Member

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

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature Good First Issue Issue particularly suitable to be worked on by new contributors [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Jun 25, 2024
@westonruter westonruter changed the title Preload links can be sent via Link HTTP response headers instead of link tags Jun 25, 2024
@AhmarZaidi
Copy link
Contributor

Hey, I'd like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Issue particularly suitable to be worked on by new contributors [Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature
2 participants