Send preload links via HTTP Link headers in addition to LINK tags#1323
Send preload links via HTTP Link headers in addition to LINK tags#1323westonruter merged 10 commits intoWordPress:trunkfrom
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. |
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
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.
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.
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
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_Collectionto construct the Link HTTP response headers for preloading resources.od_optimize_template_output_bufferto callheaders()if there are preload links available and headers have not been sent already.Cannot modify header information - headers already senterror due to output before sending headers.