[Idea] Detect/fix font-display: swap #317
sashee posted onGitHub
I've just got bit by the font-display=swap
property. It's mentioned in the docs that:
Google Web Fonts by default appends ?display=swap to their URLs. Make sure to remove it to ensure the video renders correctly if you have a slow internet connection.
But it turns out it's not just keeping in mind to remove the query parameter when I copy-paste the font URL as 3rd-party dependencies could also hardcode it in their code (example).
This got me thinking how to solve this automatically.
As the rendering process has access to the network requests the page makes (ref), it could warn if there is a request that goes to the Google Web Fonts URL with ?display=swap
. This would be a helpful warning message during the rendering. Maybe it's even possible to do this using a Service Worker in the preview.
But it can go further. The rendering could also check the results of CSS requests and see if there is a font-display: swap
in them. This would make it not specific to Google Web Fonts. On the other hand, it might flag false positives.
But it can go further still. I think there is no need for font-display: swap
during rendering ever. So the browser could remove that from all CSS responses (maybe even from inline CSS). This would solve this problem for good, and a hidden hardcoded ?display=swap
wouldn't result in flickering.