-
Notifications
You must be signed in to change notification settings - Fork 109
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
Send preload links via HTTP Link headers in addition to LINK tags #1323
Conversation
Please add type label and milestone. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Great start.
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
Oh, we'll also need to add tests for this new method. |
- Remove code duplication - Update escaping functions - Update documentation - Handle no headers case
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
- Deduplicate adjacent links - Add media attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close!
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
Had some doubts regarding tests implementation:
Then |
- Update documentation - Fix preload link without href using about:blank fallback
@AhmarZaidi Yeah, testing the output of |
1200 | ||
); | ||
|
||
$expected_header = 'Link: <https://example.com/foo.jpg>; rel="preload"; as="image"; fetchpriority="high"; imagesrcset="https%3A%2F%2Fexample.com%2Ffoo-480w.jpg%20480w%2C%20https%3A%2F%2Fexample.com%2Ffoo-800w.jpg%20800w"; imagesizes="%28max-width%3A%20600px%29%20480px%2C%20800px"; crossorigin="anonymous"; media="screen", <https://example.com/bar.jpg>; rel="preload"; as="image"; fetchpriority="high"; imagesrcset="https%3A%2F%2Fexample.com%2Fbar-480w.jpg%20480w%2C%20https%3A%2F%2Fexample.com%2Fbar-800w.jpg%20800w"; imagesizes="%28max-width%3A%20600px%29%20480px%2C%20800px"; crossorigin="anonymous"; media="screen%20and%20%28min-width%3A%20600px%29%20and%20%28max-width%3A%201200px%29"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imagesrcset
, imagesizes
, and media
attribute values here seem wrong being URL-encoded. Do these work being encoded like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. I found it doesn't work, for imagesrcset
at least. I tried sending that Link
header on a Glitch and I saw a network request attempted for:
https://alert-sustaining-acrylic.glitch.me/https%3A%2F%2Fexample.com%2Ffoo-480w.jpg%20480w%2C%20https%3A%2F%2Fexample.com%2Ffoo-800w.jpg%20800w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I got this. See d1cd8d4
plugins/optimization-detective/class-od-preload-link-collection.php
Outdated
Show resolved
Hide resolved
Great work! |
Summary
Fixes #1321
Relevant technical choices
get_headers()
toOD_Preload_Link_Collection
to construct the Link HTTP response headers for preloading resources.od_optimize_template_output_buffer
to callheaders()
if there are preload links available and headers have not been sent already.Cannot modify header information - headers already sent
error due to output before sending headers.