WordPress在头部添加dns-prefetch,应该是为了从s.w.org预获取表情和头像,目的是提高网页加载速度 ,但s.w.org国内根本无法访问,什么预获取、什么提高速度,都是泡影,不仅没用处,反而可能会影响速度,那就禁止它。
将下面的代码添加到主题functions.php
模板中:
remove_action( 'wp_head', 'wp_resource_hints', 2 ); remove_action( 'wp_head','rest_output_link_wp_head'); remove_action( 'wp_head','wp_oembed_add_discovery_links'); remove_action( 'template_redirect', 'rest_output_link_header', 11 );
推荐第二种方法:修改functions.php
//去除s.w.org 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 );
- 测试
curl -I www.fanlog.org
设置前的响应
设置后的响应
另外一种测试方式
curl -I -A 'chrome' https://www.fanlog.org
测试通过
- chrome的lighthouse本地测试
桌面端
参考资料
- http://www.mlwei.com/1461.html
- https://wordpress.stackexchange.com/questions/211467/remove-json-api-links-in-header-html
- https://www.itbulu.com/disable-s-w-org.html
- https://www.xiapilu.com/web/web-tutorial/wordpress-api-json.html