Security, Tech & Programming
Load google fonts using javascript

Load google fonts using javascript

We can load google fonts using javascript, resulting in better google pagespeed score.

<script defer src=""></script>
<script defer>
	google: {
		families: ['Tangerine:300i,400i,700,700i', 'Open Sans:300']

Google webfonts loader also allows us to set a timeout before loading the google fonts.

The code would look like this:

WebFontConfig = {
  google: {
    families: ['Droid Sans']
  timeout: 2000 // Set the timeout to two seconds

For more info:

Note: we can also load custom font files using webfontloader. More details on their github page.

Leave a Reply

Your email address will not be published. Required fields are marked *

Hire Me!