字体是怎么搬回自己家的
字体一直问 Google 要。首屏先等 CSS,再等字体,手机上最贵的是那一段空白。
起点
做法
只留站上用到的字,切成一个 woff2,文件名带内容哈希。
const font = '/font/noto-serif-sc.76636729.woff2'结果
首页少了一个外部域名,字体文件从 1.3MB 降到 485KB。慢速 4G 下,第一行字早了半秒。
起点
フォントはずっと Google に頼んでいた。最初の画面はまず CSS を待ち、次にフォントを待つ。スマホでいちばん高いのは、その空白の時間だ。
做法
サイトで使う文字だけを残し、一つの woff2 に切る。ファイル名に内容のハッシュを入れる。
const font = '/font/noto-serif-sc.76636729.woff2'结果
最初の画面から外部ドメインが一つ消え、フォントは 1.3MB から 485KB になった。低速の 4G でも、最初の行が半秒早く出る。
起点
폰트는 늘 Google에 물어봐야 했다. 첫 화면은 먼저 CSS를 기다리고, 다음은 폰트를 기다린다. 휴대폰에서 가장 비싼 것은 그 빈 시간이다.
做法
사이트에서 쓰는 글자만 남겨 하나의 woff2로 자른다. 파일 이름에 내용 해시를 넣는다.
const font = '/font/noto-serif-sc.76636729.woff2'结果
첫 화면에서 외부 도메인이 하나 사라지고, 폰트는 1.3MB에서 485KB가 되었다. 느린 4G에서도 첫 줄이 반 초 빨리 나온다.
Starting point
The font always had to ask Google. The first screen waits for CSS, then waits for the font. On a phone, that blank stretch is the most expensive part.
What I did
Keep only the characters the site uses, cut them into one woff2, and put a content hash in the filename.
const font = '/font/noto-serif-sc.76636729.woff2'Result
One external domain disappeared from the first screen, and the font went from 1.3MB to 485KB. On slow 4G the first line arrives half a second earlier.
留言
5 条正在读…