Select Page

CDN加速前端公共库 JS、Google Fonts、Ajax 、Gravatar

CDN加速前端公共库 JS、Google Fonts、Ajax 、Gravatar
由于众所周知的原因,大多数国外开源的 JS 库虽然采用 CDN 托管方式但在国内访问速度感人。360的CDN经常抽风,Google在北京和台湾的服务器也不定时抽风,正好我在搜索的时候找到了这个公益项目,他们托管了 CDNJS 的所有开源 JS 库以及反代了 Google Fonts、Ajax 和 Gravatar,全部支持 http 和 https。
CDNJS 开源 JS 库

采用的方法是每天定时同步 CDNJS 的Github

https://github.com/cdnjs/cdnjs?utm_source=sb.sb

所有的JS/CSS库链接

https://cdnjs.cat.net/ajax/libs/

如果使用 cdnjs.com 只需要替换 cdnjs.cloudflare.com 为 cdnjs.cat.net 即可,如

<script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js”></script>

替换成

<script src=”https://cdnjs.cat.net/ajax/libs/jquery/3.2.1/jquery.min.js”></script>

Google Fonts

采用的方法是万能的 Nginx 反代 + 关键词替换

使用的时候,只需要替换 fonts.googleapis.com 为 fonts.cat.net 即可,如

<link href=’https://fonts.googleapis.com/css?family=Open+Sans’ rel=’stylesheet’>

替换成

<link href=’https://fonts.cat.net/css?family=Open+Sans’ rel=’stylesheet’>

如只需更换单个字体,只需把 fonts.gstatic.com 替换成 gstatic.cat.net 或 themes.googleusercontent.com 替换成 themes.cat.net 即可,如
https://fonts.gstatic.com/s/opensans/v14/K88pR3goAWT7BTt32Z01mxJtnKITppOI_IvcXXDNrsc.woff2
Google 前端公共库
方法同上,直接替换 ajax.googleapis.com 为 ajax.cat.net 即可,如

<script type=’text/javascript’ src=’https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js’></script>

替换成

<script type=’text/javascript’ src=’https://ajax.cat.net/ajax/libs/jquery/3.2.1/jquery.min.js’></script>

Gravatar 头像

WP4.2之后版本,打开wordpress程序目录的wp-includes文件夹,打开link-template.php,将大约第3604行的

$url = sprintf( 'http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash );

替换成

$url = sprintf( 'http://cn.gravatar.com/avatar/%s', $email_hash );

方法还是同上,直接替换 *.gravatar.com 为 gravatar.cat.net 即可,如
https://secure.gravatar.com/avatar/8406d089bc81b664a2610b8d214c1428
替换成
https://gravatar.cat.net/avatar/8406d089bc81b664a2610b8d214c1428
赞助商

国内外 CDN 均由 Cat Networks K.K.赞助
SSL 证书由 SSL.DO赞助

参考链接

About The Author

Jackie Sung

Jackie Sung, also known by his nick-name KK, always strives for the best and learn from the best. Influenced by the age of Internet, for the last few years, in his spare time, he's been working and living as a Freelance Web Engineer/ Web Developer & Designer/ Amateur Photographer/ Husky Lover. The work he provides is of highest quality, fully-customized responsive, and tested in a wide range of devices, which typically covers both front-end (HTML5/ CSS3/ JavaScript) and back-end (WordPress as the CMS) responsibilities.

Leave a reply

电子邮件地址不会被公开。 必填项已用*标注

19 − 17 =