Converting and rendering web fonts to base64 - keep original look

前端 未结 2 475
野趣味
野趣味 2020-11-30 22:08

I want to defer font loading on my site inspired by deferred font loading logic for Smashing Magazine.

Main part of this is converting fonts to base64 and preparing

2条回答
  •  情话喂你
    2020-11-30 22:47

    Use this code snippet to base64 encode your font directly in the browser (OS independent, no need to install anything)

    function base64convert (files) {
      console.clear()
      const reader = new FileReader()
      reader.onload = (e) => {
        console.log(e.target.result)
      }
      reader.readAsDataURL(files[0])
    }

    Then copy the output and paste it into your CSS:

    @font-face {
        font-family: 'myfont';
        src: url("<>");
    }
    

提交回复
热议问题