Paulund
2018-07-14 #javascript

Load Google Fonts Async

When you run your website through Google PageSpeed it will highlight the Google web font script as a render blocking file.

Using the WebFontLoader to load the web fonts on the page with async and therefore removing the render-blocking on this file.

<script type="text/javascript">
  WebFontConfig = {
    google: { families: [ 'Roboto' ] }
  };
  (function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
      '://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
    wf.type = 'text/javascript';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
  })();
  // ]]>
</script>