USTC blog 强制对 Google 字体加速

自从 Google 抽风之后,WordPress 默认的 Google 字体也就跟着抽风了,表现就是 blog 页面需要 “花很长时间才能打开”。之前我们通过修改 WordPress 源码的方式,将 Google Fonts “劫持” 到 LUG 搭建的代理(传送门),但 WordPress 主题升级之后修改就被覆盖了。因此采用了 @zsj 的建议,对 WordPress 输出的内容进行文本替换,将 Google 字体 URL 强制替换为 LUG 搭建的代理。

技术细节:在 nginx 服务器上,把 WordPress 输出的 MIME type 为 text/html text/css text/javascript text/xml 的内容中的 URL 做如下字符串替换:(Updated 2014-08-05)

fonts.googleapis.com         fonts.lug.ustc.edu.cn
ajax.googleapis.com          ajax.lug.ustc.edu.cn
themes.googleusercontent.com google-themes.lug.ustc.edu.cn
fonts.gstatic.com            fonts-gstatic.lug.ustc.edu.cn

《USTC blog 强制对 Google 字体加速》上有20条评论

      1. 资源使用https加载没有问题。主要是反过来,如果网页用https访问,资源用http的话就会被浏览器抱怨或者拒绝。现在blog是强制https的吗?

        Anyway,我只是提一下有这个东西而已。

        1. 现在 blog 对 UA 是浏览器且非 IE6/IE7 的强制 https,其他的不做跳转。由于 XP 不支持 StartSSL 的证书,所以不做跳转。

          1. 你们怎么设置

            现在 blog 对 UA 是浏览器且非 IE6/IE7 的强制 https,其他的不做跳转。由于 XP 不支持 StartSSL 的证书,所以不做跳转。

            能把做法或者nginx配置贴出来么?

    1. 现在已经改成了不匹配 http 或 https,只匹配 //fqdn/。用户有可能写 //fqdn 这种形式的 URL,早先的正则表达式不能匹配。

  1. nginx的替换规则要怎么写?

    sub_filter fonts.googleapis.com fonts.lug.ustc.edu.cn;
    sub_filter ajax.googleapis.com ajax.lug.ustc.edu.cn;
    sub_filter themes.googleusercontent.com google-themes.lug.ustc.edu.cn;
    sub_filter fonts.gstatic.com fonts-gstatic.lug.ustc.edu.cn;
    sub_filter_types text/html text/css text/javascript text/xml;
    sub_filter_once off;

    这样写对不对。

评论已关闭。