Skip to main content

Load Google Font Asynchronously

By May 22, 2017Blog, Javascript
Allure Web Solutions Code Snippet

The below snippet shows how to load Google Fonts asynchronously. The main benefit of loading fonts asynchronously is that it speeds up the site extensively.

(function ($, window, undefined) {
    // Load Google Fonts Asynchronously with two sample fonts (Roboto Condensed and Lato)
    window.WebFontConfig = {
        google: {families: ['Roboto+Condensed:400,700:latin', 'Lato:400,700:latin']}
    (function () {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
})(jQuery, window);



Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017