fonts.googleapis.com加载慢解决办法

来源:互联网 发布:怎么成为淘宝客? 编辑:程序博客网 时间:2024/04/28 17:10
  • 前段时间帮朋友搭建了一个WordPress博客,由于博客主题中引用了google字体库(fonts.googleapis.com)中的字体,导致网站打开速度超级慢,在国内使用google提供的大多少网络服务都比较慢,建议最好不要使用。

    卡在fonts.googleapis.com不动,最简单的方法就是把google提供的字体下载到本地直接使用,方法如下:

    首先在网站源码head中找到类似下面的代码:

    <link rel='stylesheet' id='twentyfourteen-lato-css'  href='//fonts.googleapis.com/css?family=Lato%3A300%2C400%2C700%2C900%2C300italic%2C400italic%2C700italic' type='text/css' media='all' />

    打开其中的url(可能需要爬墙或者修改host的方式),发现全是如下这样的引用地址,我们只要将其中的字体文件下载到本地,替换其中URL,把该文件另存为font.css,上传服务器

    @font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 300;
    src: local('Lato Light'), local('Lato-Light'), url(http://themes.googleusercontent.com/static/fonts/lato/v7/KT3KS9Aol4WfR6Vas8kNcg.woff) format('woff');
    }
    @font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 400;
    src: local('Lato Regular'), local('Lato-Regular'), url(http://themes.googleusercontent.com/static/fonts/lato/v7/9k-RPmcnxYEPm8CNFsH2gg.woff) format('woff');
    }
    @font-face {
    font-family: 'Lato';
    font-style: normal;
    font-weight: 700;
    src: local('Lato Bold'), local('Lato-Bold'), url(http://themes.googleusercontent.com/static/fonts/lato/v7/wkfQbvfT_02e2IWO3yYueQ.woff) format('woff');
    }

    在WordPress模板文件中找到functions.php
    将本地URL加上并使用“//”注释掉引用google字体库部分即可。

    function twentyfourteen_font_url() {
    $font_url = '//www.amznz.com/wp-content/themes/twentyfourteen/fonts/fonts.css';
    /*
    * Translators: If there are characters in your language that are not supported
    * by Lato, translate this to 'off'. Do not translate into your own language.
    */
    // if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
    // $font_url = add_query_arg( 'family', urlencode( 'Lato:300,400,700,900,300italic,400italic,700italic' ), "//fonts.googleapis.com/css" );
    // }
    return $font_url;
    }

    Google打不开、Gmail打不、Google Analytics打不开、Google快照打不开可参看以下文章:
    Google打不开解决办法

     

    号外:
    如果懒得折腾,可以使用360网站卫士最新服务:前端公共库、Google公共库以及Google字体库,依托360全国CDN节点,360公共库提供的服务覆盖电信、联通、移动等主流运营商线路,您可以在自己的网页上直接通过替换Google库的url来引用这些资源,让网站访问速度瞬间提速!

    360提供google字体库

    地址:http://libs.useso.com

    © 原文地址: http://www.amznz.com/fonts-googleapis-com-load-slow/
    版权所有!如转载文章,请务必注明以上引用地址,否则请勿转载!
0 0