Оптимизирую сайт с помощью google page speed. И никак не могу исправить проблему со шрифтами. Из за загрузки шр шрифтов падает
Time to Interactive
и
Largest Contentful Paint
и
First Contentful Paint
Вот как я подключаю шрифты:
Способ 1 - Подключение со своего сервера:
styles.scss
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 100;
src: url('/assets/fonts/Montserrat-Thin.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 200;
src: url('/assets/fonts/Montserrat-ExtraLight.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 300;
src: url('/assets/fonts/Montserrat-Light.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 400;
src: url('/assets/fonts/Montserrat-Regular.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 500;
src: url('/assets/fonts/Montserrat-Medium.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 600;
src: url('/assets/fonts/Montserrat-SemiBold.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 700;
src: url('/assets/fonts/Montserrat-Bold.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 800;
src: url('/assets/fonts/Montserrat-ExtraBold.woff2');
}
@font-face {
font-display: swap;
font-family: 'Montserrat';
font-style: normal;
font-weight: 900;
src: url('/assets/fonts/Montserrat-Black.woff2');
}
index.html
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="preload" href="/assets/fonts/Montserrat-Thin.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-ExtraLight.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-Light.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-ExtraBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="/assets/fonts/Montserrat-Black.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
Способ 2 - Подключение с google fonts:
fonts.scss
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700;800;900&display=swap');
index.html
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>