I created and deployed a Nuxt project, and Google Pagespeed points out (rightfully) that my fonts are not preloaded when displaying the page, which hurts my PageSpeed score a lot.
I already checked this question: nuxt.js - preload .woff fonts loaded as @font-face and also this issue: https://github.com/nuxt/nuxt.js/issues/1508, but I could not fix the problem. Here is what I tried...
Currently my fonts are loaded in assets/scss/_text.scss:
@font-face {
font-family: Raleway-Medium;
src: url("~assets/fonts/Raleway/Raleway-Medium.woff2");
}
// ...
Then in assets/scss/main.scss:
@import '~assets/scss/_text.scss';
// ...
And finally in nuxt.config.js:
export default {
// ...
css: ['@/assets/scss/main.scss'],
// ...
render: {
bundleRenderer: {
shouldPreload: (_file, type) => {
console.log(_file, type)
return ['script', 'style', 'font'].includes(type)
}
}
},
}
Unfortunately, my fonts are not preloaded at all. Actually, the console.log I added in the bundleRenderer function does not even find any font or style file, here is what is logged:
runtime.js script
commons.app.js script
vendors.app.js script
app.js script
Does anyone know how I can fix this? Thanks a lot!