清理主题文件,加速Wordpress
Wednesday, January 23rd, 2008Wordpress性能差、速度慢是出了名的,加速Wordpress除了安装一些缓存/静态化插件,例如WP-Cache、WP-Super-Cache和Cos-Html-Cache,还可以通过清理主题文件中的一些数据库查询语句,减少Http请求次数,达到优化的目的。
Wordpress主题文件中经常会用到的查询语句主要有以下几个,这些语句完全可以去除或转化为静态方式而无须访问数据库 :
<html xmlns=”http://www.w3.org/1999/xhtml” <?php language_attributes() ?>> 转化为
<html lang=”zh-CN“ dir=”ltr“ xmlns=”http://www.w3.org/1999/xhtml“><meta http-equiv=”content-type” content=”<?php bloginfo(’html_type’) ?>; charset=<?php bloginfo(’charset’) ?>” /> 转化为
<meta content=”text/html; charset=UTF-8“ http-equiv=”content-type“/><meta name=”description” content=”<?php bloginfo(’description’) ?>” />转化为
<meta name=”description” content=”这里直接输入你的博客简介” /><meta name=”generator” content=”WordPress <?php bloginfo(’version’) ?>” /> 这句可以删除
<link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(’stylesheet_url’); ?>” /> 直接写出style.css文件的链接地址
<link rel=”alternate” type=”application/rss+xml” href=”<?php bloginfo(’rss2_url’) ?>” /> 直接写出RSS的链接地址
<link rel=”pingback” href=”<?php bloginfo(’pingback_url’) ?>” /> 直接写出pingback的链接地址
以此类推,凡是可以变为静态方式的地方都直接写出具体内容,这些语句大都存在于header.php和footer.php文件中,通过这番清理,大概可以减少10多次的数据库查询。
想进一步优化Wordpress的朋友还可以参考下面两篇文章介绍的方法 : 《优化Wordpress-wp终极优化手册》、《加快WordPress的页面生成和载入速度》。
注 : 本文参考了Speed up and clean up your WordPress!。
