• HOME
  • DOCS
  • WTF
  • TECH
  • LIFE
  • PAGES
    • ARCHIVE
    • TAGS
    • ABOUT
    • FRIENDS
    • RSS
  • TOOLS
    • GEO
    • RANDOM()
    • GOO.GL
    • CSS HEART
Aj's Blog

记录时间溜走的瞬间和折腾过的那些事

WP清理、加速
2014-05-07 @ TECH admin-headerCDNremove_actionwordpresswp_headwp-login优化删除open-sans加速3

一、加速
主要JS全部走CDN,几个常用JS加速CDN推荐:
七牛CDN: http://www.staticfile.org/
又拍云JS库: http://jscdn.upai.com/
BAE公共库: http://developer.baidu.com/wiki/index.php?title=docs/cplat/libs
SAE公共资源: http://sae.sina.com.cn/doc/services/libraries.html

当前模版中functions.php,清理html代码:

clear_head();
function clear_head()
{
    remove_action( 'wp_head', 'feed_links_extra', 3 );
    remove_action( 'wp_head', 'feed_links', 2 );
    remove_action( 'wp_head', 'rsd_link' );
    remove_action( 'wp_head', 'wlwmanifest_link' );
    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
    remove_action( 'wp_head', 'wp_generator' );
    remove_action( 'wp_head', 'rel_canonical' );
    remove_action( 'wp_head', 'wp_shortlink_wp_head' );
}

替换主要JS,并在代码最后调用

add_action( 'get_footer' , 'bootstrap_js' );
function bootstrap_js()
{
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js' );
    wp_enqueue_script( 'jquery' );

    wp_register_script( 'bootstrap', 'http://cdn.staticfile.org/twitter-bootstrap/3.0.0/js/bootstrap.min.js' );
    wp_enqueue_script( 'bootstrap' );
}

二、去掉gooleapi的fonts
因为众所周知的原因,googleapis在国内的速度实在太慢,把网站速度托慢了太多,比如open-sans、jquery等的调用
后台去掉open-sans,需要修改2个地方:

wp-login.php
    找到
    wp_admin_css( 'login', true );
    到此行之上追加
    wp_deregister_style('open-sans');
    wp_register_style('open-sans',false);

wp-admin/admin-header.php
    找到
    wp_enqueue_style( 'colors' );
    到此行之上追加
    wp_deregister_style('open-sans');
    wp_register_style('open-sans',false);

前台模版中有用到的方法也类似,可以google一下”wordpress remove open-sans”

下一篇:   DD-WRT无线设置详解
上一篇:   DD-WRT花生壳更新问题: RC_IP_RECV_ERROR (0x15)
  • masofeng says:
    July 16, 2014 at 20:51

    如果是原创,给你点32个赞

    Reply
  • Demon says:
    May 25, 2014 at 03:08

    具体您所说的方式? 是直接在自己主题中的functions.php中加入代码即可?? 本人是前端,不太了解

    Reply
    • Aj says:
      May 25, 2014 at 03:40

      是。
      我正在用。
      一是针对前台。
      二是针对后台。

      Reply
  • Cancel reply