第一:去掉一些不用的html head内容,让页面更小 在function.php中加入:
remove_action( ‘wp_head’, ‘wp_generator’); remove_action( ‘wp_head’, ‘wlwmanifest_link’); remove_action( ‘wp_head’, ‘rsd_link’); remove_action( ‘wp_head’, ‘index_rel_link’ ); remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 ); remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 ); remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 ); remove_action( ‘wp_head’, ‘feed_links’, 2 ); remove_action( ‘wp_head’, ‘feed_links_extra’, 3 ); remove_action( ‘wp_head’, ‘wp_print_head_scripts’, 9 ); remove_action( ‘wp_head’, ‘rel_canonical’ ); remove_action( ‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0 );
第二:去掉一些定时任务,这些定时任务会频繁访问数据库和网络 在function.php中加入:
remove_action( ‘init’, ‘wp_schedule_update_checks’ ); remove_action( ’load-plugins.php’, ‘wp_update_plugins’ ); remove_action( ’load-themes.php’, ‘wp_update_themes’ ); remove_action( ’load-update-core.php’, ‘wp_update_plugins’ ); remove_action( ’load-update-core.php’, ‘wp_update_themes’ ); remove_action( ’load-update.php’, ‘wp_update_plugins’ ); remove_action( ’load-update.php’, ‘wp_update_themes’ ); remove_action( ‘upgrader_process_complete’, ‘wp_update_plugins’ ); remove_action( ‘upgrader_process_complete’, ‘wp_update_themes’ ); remove_action( ‘upgrader_process_complete’, ‘wp_version_check’ ); remove_action( ‘wp_maybe_auto_update’, ‘wp_maybe_auto_update’ ); remove_action( ‘wp_update_plugins’, ‘wp_update_plugins’ ); remove_action( ‘wp_update_themes’, ‘wp_update_themes’ ); remove_action( ‘wp_version_check’, ‘wp_version_check’ );
第三:卸载低效的插件
Better Related Content: 自动在文章中插入相关文章。它查询相关文章的sql是相当费劲的
Baidu Sitemap Generator:生成百度的sitemap,当你更新文章的时候,sitemap文件自动更新,每天定时也会更新,当文章很多的时候,这个也是相当费劲的,我的博客在百度站长上也没有提交sitemap的权限。这个插件也没必要的。
第四:开启apache过期时间
使用apache使用mod_expires插件 IfModule mod_expires.c> ExpiresActive on ExpiresDefault “access plus 10 minutes” ExpiresByType image/gif “access plus 3 months” ExpiresByType image/png “access plus 3 months” ExpiresByType text/css “access plus 3 months” ExpiresByType application/x-javascript “access plus 3 months”
这样在静态资源返回给浏览器的响应头里会有个Expires字段,表示资源的过期时间。在过期时间内,浏览器会用本地缓存而不是重复去服务端请求。 否则你浏览页面里只要有这些静态资源,浏览器都会去访问一遍服务器,虽然服务器会返回一个HTTP 304,表示资源未更新,但这也是不必要的请求。
第五:设置swap
如果你的内存很小,你不使用swap的话,你的程序必挂无疑。 创建一个512MB的文件作为swap分区 dd if=/dev/zero of=/swapfile bs=512M count=1024 mkswap /swapfile swapon /swapfile 编辑fstab文件,增加 /swapfile swap swap default 0 0
第六:清理一下数据库的垃圾数据 安装一个 WP Clean Up插件,可以清理草稿,修订版,垃圾评论等垃圾数据。还可以优化数据库。