bigcommerce / paper-handlebars

Paper plugin for rendering via Handlebars.js
BSD 4-Clause "Original" or "Old" License
12 stars 36 forks source link

[STRF-10096] - storefront - investigate google fonts css uri encoding issue #197

Closed rafa-avila-bc closed 2 years ago

rafa-avila-bc commented 2 years ago

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_step1

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

How was it tested?

Unit tests.


cc @bigcommerce/storefront-team