preloadinggoogle-fonts

How to preload google fonts correctly


How to preload google fonts correctly, without warning in the console?

enter image description here

Here my code:

<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;600;700&family=Open+Sans:wght@100;400;700&display=swap"
          rel="preload" as="style" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;600;700&family=Open+Sans:wght@100;400;700&display=swap"
          rel="stylesheet">

I have already added the crossorigin attribute to preload link, but the warning is still here


Solution

  • Just add crossorigin attribute to main stylesheet

    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;600;700&family=Open+Sans:wght@100;400;700&display=swap"
              rel="preload" as="style" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;400;600;700&family=Open+Sans:wght@100;400;700&display=swap"
              rel="stylesheet" crossorigin="anonymous">