LoginSignup
0
1

More than 5 years have passed since last update.

google fonts preload でちゃんと読み込み

Posted at

そうだ。Google fonts を preload しよう。

参考
https://firstlayout.net/optimize-google-fonts-with-preload/

・今回は Kosugi Maru をダウンロード
google webfonts helper

・WOFF2のみサーバーにアップロード
そしてheadタグ内のCSSの最初の方で以下を読み込み。
一応フォントへのパスは絶対パスにするほうがAMPにも対応するので良いみたい。


<link rel="preload" as="font" href="/fonts/kosugi-maru-v3-japanese_latin-regular.woff2" crossorigin>

フォント使うようにCSS設定。


        @font-face {
            font-display: swap;
            font-family: 'Kosugi Maru';
            font-style: normal;
            font-weight: 400;
            src: local('Kosugi Maru'), local('KosugiMaru-Regular'),
            url('/fonts/kosugi-maru-v3-japanese_latin-regular.woff2') format('woff2');
        }

body {
      font-family: 'Kosugi Maru', sans-serif;
     }

これでOK!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1