TypeCodes

博客优化第二波(四):wordpress头部文件的清理

前几天跟sparrowwei聊天,讨论博客空间访问速度的问题。一经比较,发觉自己的博客一些程序文件存在很多冗余信息,这些影响了博客的加载速度。遂下决心,彻底整理下博客,提高访问速度,于是开启了博客优化第二波进程。现将整个清理过程记录如下(主要还是头部文件的清理,产生这些冗余信息的是wp_head()函数):

(一)选择sinaapp的jQuery库,合并JS文件

1、在 wordpress添加滚动(单条或多条)公告 一文中提到了使用谷歌的jQuery库,但是你懂得,所以改用新浪开放平台的了;

2、合并评论引用quote.js和评论前面加@的reply.js为quote_reply.js,减少请求次数;合并滚动公告notice.js到主题weisay.js。然后根据页面的需要,通过is_singular函数判断是否加载quote_reply.js(因为它们只会在博客需要评论的地方出现),而整合notice.js的weisay.js需要在任何页面都加载,因为每个页面都会用到右侧栏的公告栏。

(二)重点:整理header.php,去掉多余的信息

经过sparrowwei的提醒,看下自己的<head>之间的信息,确实存在问题:

<link rel="alternate" type="application/rss+xml" title="TypeCodes RSS Feed" href="https://typecodes.com/?feed=rss2" />
<link rel="alternate" type="application/atom+xml" title="TypeCodes Atom Feed" href="https://typecodes.com/?feed=atom" />
<link rel="pingback" href="https://typecodes.com/xmlrpc.php" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="https://typecodes.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="https://typecodes.com/wp-includes/wlwmanifest.xml" /> 
<meta name="generator" content="WordPress 3.4.0" />

[WP官方解决代码](http://wordpress.org/support/topic/remove-feed-from-wp_head)如下在functions.php中添加如下代码

//sorted by vfhky
remove_action( 'wp_head', 'feed_links_extra', 3 ); //去除评论feed
remove_action( 'wp_head', 'feed_links', 2 ); //去除文章feed
remove_action( 'wp_head', 'rsd_link' ); //针对Blog的远程离线编辑器接口
remove_action( 'wp_head', 'wlwmanifest_link' ); //Windows Live Writer接口
remove_action( 'wp_head', 'index_rel_link' ); //移除当前页面的索引
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); //移除后面文章的url
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); //移除最开始文章的url
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );//自动生成的短链接
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); ///移除相邻文章的url
remove_action( 'wp_head', 'wp_generator' ); // 移除版本号

函数说明:

remove_action($tag, $function_to_remove, $priority, $accepted_args);
tag变量表示将要被删除的函数所连接到的动作hook;
function_to_remove变量表示将要被删除函数的名称;
priority变量表示函数优先级(在函数最初连接时定义,默认为10;
accepted_args变量表示函数所接受参数的数量,默认为1。
(三)严重失误:

把博客的ping功能去掉了,直接导致博客发布文章后没及时通知百度搜索……于是,重新在header.php中添加上代码

<link rel="pingback" href="<?php bloginfo('pingback_url'); ?/>" />
打赏支持

Comments »