probberechts / hexo-theme-cactus

:cactus: A responsive, clean and simple theme for Hexo.
https://probberechts.github.io/hexo-theme-cactus/
MIT License
3.2k stars 784 forks source link

Chinese characters load very slowly #373

Closed fps144 closed 1 month ago

fps144 commented 1 year ago

When Chinese characters appear on the page, it always loads very slowly. The font file 'MesloLGS-Regular.ttf' takes a very long time. Can this be optimized? Or what should I do?

Exception0x0194 commented 2 months ago

Directly add font files into resources is not very practical, for Chinese font files are usually large and takes a long time to transmit (especially when you deploy websites on servers with low bandwidth).

You can use CDN to deliver fonts from elsewhere with larger bandwidth; also CDNs split font file (by unicode range) in beforehand, so user only need to load required parts.

To change fonts used in the theme, and change font source to CDN:

  1. Specify new font families in cactus/source/_variables.styl, change original font families (for example from Meslo to Noto Sans SC for better Chinese display);

  2. Add font from CDN as CSS: import font link in site header specified in cactus\layout\_partial\head.ejs before </head> marker:

    <link rel="stylesheet" type="text/css" href="https://fonts.font.im/css?family=Noto+Sans+SC:normal,bold">

    By this you import Noto Sans SC medium and bold from CDN.

  3. You can also delete original font files in cactus/sources/lib/Meslo* and cactus/sources/lib/vazir* to make site resources smaller.

In this way fonts should load faster than load from site resources.