Last active
January 13, 2022 23:15
-
-
Save m-allanson/25c24f4790c7768a06ed52e160ab576b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a preload link pointing to myFonts' licence counting url. This | |
* allows hits to the site to register as font requests with myFonts, but | |
* ensures that we are not blocking CSS rendering by waiting for this request | |
* to complete. | |
* | |
* This avoids having to include the following in a CSS file: | |
* @import url("//hello.myfonts.net/count/<id>"); | |
* | |
* Refs: | |
* https://stackoverflow.com/questions/23045705/how-the-licensed-web-font-is-getting-rendered | |
* https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content | |
*/ | |
const React = require("react"); | |
exports.onRenderBody = function({ setHeadComponents }, pluginOptions) { | |
setHeadComponents([ | |
React.createElement("link", { | |
key: "fonts", | |
href: `//hello.myfonts.net/count/${pluginOptions.myFontsId}`, | |
rel: "preload", | |
as: "style" | |
}) | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! 👍