zoukankan      html  css  js  c++  java
  • wordpress优化细节:屏蔽s.w.org和移除emoji加快打开速度

    在使用wordpress主题时,经常发现使用国外的主题打开网站很慢,尤其是文章页,后来发现这是由于Wordpress的服务器在国外,在wordpress 4.2版本之后增加了emoji表情外部调用,后为了提高页面的加载速度,wordprses 4.6版本之后在head中增加dns-prefetch用来从s.w.org获取表情和头像,但是由于国内网络访问问题,在打开网页时会发现在浏览器左下角一直在显示“等待s.w.org…”或“正在获取s.w.org..”之类的提示,也就是说这东西在国内不仅没用处还影响网页加载速度。而且对于部分wordpress用户来说并不需要这东西,那么禁止它就非常有必要.

    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 );
    

      

  • 相关阅读:
    Postman提取接口返回值设置变量
    Python-浅拷贝与深拷贝
    Python列表
    typeorm查询两个没有关联关系的实体
    springboot去掉数据源自动加载
    docker搭建redis集群
    实习工作记录(一)大文件上传vue+WebUploader
    js重点之promise
    css重点
    git简单命令整理
  • 原文地址:https://www.cnblogs.com/huxiaoyi/p/11134019.html
Copyright © 2011-2022 走看看