解决谷歌字体库导致页面加载慢

由于众所周知的原因,谷歌WEB字体库在中国是无法正常使用的,而很多国外的著名开源程序都使用了该库,比如wordpress、opencart等等。

网上也有很多避开这个问题的方法,下面我给出2种基于Nginx的方法。

一、使用360提供的中国镜像:

subs_filter_types text/css;
subs_filter fonts.googleapis.com fonts.useso.com;

二、基于Nginx的本地化的方法:

subs_filter_types text/css;
subs_filter (https?:)?//fonts.gstatic.com/ / r;
subs_filter (https?:)?//fonts.googleapis.com/ / r;

location ~ ^/css$ {
    proxy_set_header Accept-Encoding '';
    proxy_set_header Host fonts.googleapis.com;
    proxy_pass http://fonts.useso.com;
}

location ~ ^/s/opensans/ {
    proxy_set_header Accept-Encoding '';
    proxy_set_header Host fonts.gstatic.com;
    proxy_pass http://fonts.gstatic.com;
}

提示:
1.以上配置并未启用Nginx缓存,若有需要请自行添加
2.此配置依赖Nginx第三方扩展模块subs_filter

文章作者: 若海; 原文链接: https://www.rehiy.com/post/99/; 转载需声明来自技术写真 - 若海

已有 2 条评论

  1. 好像显示起来有问题哦

    1. 第二种方法,需要你的服务器可以正常访问google字体。

添加新评论