How to host google web fonts on my own server?

前端 未结 19 1909
闹比i
闹比i 2020-11-27 09:10

I need to use some google fonts on an intranet application. The clients may or may not have internet connection. Reading the license terms, it appears that its legally allo

相关标签:
19条回答
  • 2020-11-27 09:16

    I made a tiny PHP script to get download links from a Google Fonts CSS import URL like: https://fonts.googleapis.com/css?family=Roboto:400,700|Slabo+27px|Lato:400,300italic,900italic

    You can use this tool here: http://nikoskip.me/gfonts.php

    For instance, if you use the above import URL, you will get this:

    0 讨论(0)
  • 2020-11-27 09:18

    There is a tool localfont.com to help you download all font variants. It as well generates the corresponding CSS for implementation. deprecated

    localfont is down. Instead, as Damir suggests, you can use google-webfonts-helper


    0 讨论(0)
  • 2020-11-27 09:18

    Edit: As luckyrumo pointed out, typefaces is depricated in favour of: https://github.com/fontsource/fontsource

    If you're using Webpack, you might be interested in this project: https://github.com/KyleAMathews/typefaces

    E.g. say you want to use Roboto font:

    npm install typeface-roboto --save
    

    Then just import it in your app's entrypoint (main js file):

    import 'typeface-roboto'
    
    0 讨论(0)
  • 2020-11-27 09:18

    You can download source fonts from https://github.com/google/fonts

    After that use font-ranger tool to split your large Unicode font into multiple subsets (e.g. latin, cyrillic). You should do the following with the tool:

    • Generate subsets for each language you support
    • Use unicode-range subsetting for saving bandwidth
    • Remove bloat from your fonts and optimize them for web
    • Convert your fonts to a compressed woff2 format
    • Provide .woff fallback for older browsers
    • Customize font loading and rendering
    • Generate CSS file with @font-face rules
    • Self-host web fonts or use them locally

    Font-Ranger: https://www.npmjs.com/package/font-ranger

    P.S. You can also automate this using Node.js API

    0 讨论(0)
  • 2020-11-27 09:19

    There is a very simple script, written in plain Java, to download all fonts from a Google Web Font link (multiple fonts supported). It also downloads the CSS file and adapts it to local files. The user-agent can be adapted to get also other files than only WOFF2. See https://github.com/ssc-hrep3/google-font-download

    The resulting files can easily be added to a build process (e.g. a webpack build like vue-webpack).

    0 讨论(0)
  • 2020-11-27 09:20

    In addition to k0pernicus I would like to suggest best-served-local. It's also a bash (v4) script to enable webserver operators to download and serve Google web fonts from their own webserver. But in addition to the other bash script, it lets the user fully automate (via cron and such) the serving of up-to-date font files and css-files.

    0 讨论(0)
提交回复
热议问题