我的博客

分享技术与思想的点滴

wordpress优化:屏蔽s.w.org和移除emoji或使用CDN加速

在使用wordpress时,经常发现打开网站很慢,尤其是文章页,后来发现这是由于wordpress 4.2之后增加了emoji表情外部调用,wordprses 4.6版本之后在head中增加dns-prefetch用来从s.w.org获取表情头像,但是由于国内网络GFW问题,在打开网页时会发现在浏览器一直在“等待s.w.org…”之类的提示,原本是为了提高页面加载速度的,现在不仅没用还影响网页加载速度,这是无法忍受的,果断去除,代码如下。 ``` remove_action('wp_head', 'print_emoji_detection_script', 7 ); remove_action('admin_print_scripts','print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_styles', 'print_emoji_styles'); //禁止加载s.w.org并移动dns-prefetch function remove_dns_prefetch( $hints, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { return array_diff( wp_dependencies_unique_hosts(), $hints ); } return $hints; } add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 ); ``` 但其实发现替换掉源`s.w.org`才是更好选择,或者使用`CDN加速`。