The proposed fix in this PR is that the code responsible for creating the data for early hints will use NodeJs url to parse the paths and the formated version of the valid URL will be returned so any helper using this code will then use the valid URL to generate the HTML it needs to. The url.parse method throws when it receives invalid data so it already helps us to produce valid URLs. It is important to note that NodeJs url module does not follow RFC-3986 URI model. If there is a need to comply with RFC-3986, a new package should be installed: check: https://runkit.com/embed/hrxz28cj47n1
What? Why?
After fully enabling early hints an issue with URL encoding was found: the URL for google fonts in Link headers are encoded but the same URLs in the
link
tag are not encoded, leading to requesting the fonts 2 times. Check the requests in this test https://www.webpagetest.org/result/220912_BiDcW5_D8J/1/details/#waterfall_view_step1The proposed fix in this PR is that the code responsible for creating the data for early hints will use NodeJs
url
toparse
the paths and theformat
ed version of the valid URL will be returned so any helper using this code will then use the valid URL to generate the HTML it needs to. Theurl.parse
method throws when it receives invalid data so it already helps us to produce valid URLs. It is important to note that NodeJsurl
module does not follow RFC-3986 URI model. If there is a need to comply with RFC-3986, a new package should be installed: check: https://runkit.com/embed/hrxz28cj47n1How was it tested?
Unit tests.
cc @bigcommerce/storefront-team