Closed julien51 closed 6 years ago
Could you please elaborate a bit more? Which of the font assets would get automatically preloaded by the helper? Are you suggesting the helper would only preload the font asset that is a particular match for the current browser? ...because I don't think it would necessarily help to preload all possible font asset file types. Or is preload
smart enough to recognize this for varying font assets?
Currently, for the broweser to start downloading the font files, it has to "know" about them, this means that it needs first to download the CSS files and parse them. If the browser knew about the font files faster it could download them in parallel.
I have actually solved that issue in my end by adding the following to our HTML layout fil (in the <head>
section):
<link rel="preload" href="<%= font_path('fontawesome-webfont.woff2') %>" as="font" type="font/woff2" crossorigin>
Maybe it is the simplest solution...
Cool. I'm going to close this out for now. If others feel like solving this in a more generic way (not sure about the best way to handle the possibility of different font file types), we can revisit at that time.
I'm getting the following error in the Chrome console when preloading font-awesome:
The resource was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate
as
value and it is preloaded intentionally.
@julien51 do you know how to remove the warning?
Hi! Thanks for this gem! It is generally considered good practice to
preload
some resources to make rendering pages faster. By default fonts are only loaded when they are "detected" in the CSS which can be significantly delayed.Do you think it would make sense to provide a helper to preload the font file?