有些使用Wordpress的独立主机博客运行的速度显得相当的慢,特别是当博客的流量非常大的时候,这可能是由于你的博客需要加载很多大文件或者无效代码导致的结果,可是没有什么比一个速度很慢的博客更糟的事情了。这里有一些拿来就可以用的技巧,告诉你如何给你的Wordpress博客提速,这主要是针对使用Wordpress的独立主机博客用户,如果你的博客是在Wordpress.com上,那就没有必要看了,因为Wordpress.com已经考虑到了。

1、将Wordpress和插件升级到最新版本

如果Wordpress推出新的版本,记得升级。毕竟Wordpress每次更新,都会修正一下Bug,或者开发出一些新的功能。

同样,当你所用的插件推出新版本的时候,也要记得升级,每当Wordpress升级之后,大多数插件都会随着更新,主要是为了能够适应新版本的Wordpress,同时也修正一些Bug,或者在性能上有所提升。所以,请记得让你的Wordpress和所用的插件随时保持最新版本状态。

2、禁用或删除不用的插件

这可能是导致Wordpress速度慢下来最大的原因,因为很多插件都包含大量的代码和脚本。所以,如果你不用某个插件,就把它禁用掉,或者干脆删掉!确定一下哪些插件是你必须用的,那些插件是可有可无的,把那些可有可无的全部删掉!就这么简单!

3、规范代码

规范你的代码可以适当地降低Wordpress的加载时间。以下是一些简单的规范Wordpress代码的方法,可以让你的Wordpress速度更快。

  • 减少空白
    这里的空白是指代码中的空白,很多朋友和我一样,喜欢用大量的空白(比如缩进、换行等),以便于阅读和组织代码,不过,减少空白的使用,可以提升你的Wordpress加载速度。

    使用了很多空白:

    .test {
    font-family: Georgia, Times, serif;
    font-size: 12px;
    color: #000000;
    }

    减少空白之后:

    .test { font-family: Georgia, serif; font-size: 12px; color: #000000;}

  • 使用外部脚本
    使用外部脚本替代header.php中大量的代码,这样,当你浏览同一个博客不同的页面的时候,浏览器可以不用重新加载同一个脚本。

    使用外部脚本:

    <script type=”text/javascript” src=”example.js“></script>

  • 压缩CSS代码
    压缩你的CSS代码对每个人都是有利的,对你自己,对浏览器,对访问者来说,这让你的CSS更加简洁,加载速度更快。未经压缩的CSS代码:

    .test {margin-top: 7px; margin-right: 1px; margin-bottom: 5px; margin-left: 3px;}

    压缩过的CSS代码:

    .test {margin: 7px 1px 5px 3px;}

4、减少PHP及数据库查询

最重要的是,要减少PHP及数据库查询,如果每次加载一个页面,你的浏览器都必须执行PHP,这将会增加很多的加载时间,如果我们用HTML替代PHP,那么浏览器在加载页面的时候,就只需要读取HTML就可以了。

大量的请求和查询:

<title><?php bloginfo(’name’); ?><?php bloginfo(’description’); ?></title>

<meta http-equiv=”Content-Type” content=”<?php bloginfo(’html_type’); ?>; charset=<?php bloginfo(’charset’); ?>” />

<meta name=”generator” content=”WordPress <?php bloginfo(’version’); ?>” />

<link rel=”stylesheet” href=”<?php bloginfo(’stylesheet_url’); ?>” type=”text/css” media=”screen” />

<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0″ href=”<?php bloginfo(’rss2_url’); ?>” />

<script type=”text/javascript” src=”<?php bloginfo(’template_url’); ?>/mootools.js”></script>

减少之后:

<title>Your Blog Title</title>

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

<meta name=”generator” content=”WordPress 2.3″ />

<link rel=”stylesheet” href=”http://yourdomain.com/wp-content/themes/themefolder/files/style.css” type=”text/css” media=”screen” />

<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0″ href=”http://feeds.feedburner.com/yourid” />

<script type=”text/javascript” src=”http://yourdomain.com/wp-content/themes/themefolder/files/mootools.js”></script>

原文:4 Simple Ways To Speed Up WordPress

系列:Wordpress常用技巧40则

如果你喜欢本文,你可以 订阅本站全文Feed,以便获取更多相关的信息。

转载原创文章请注明出处,本文永久链接:http://www.davidlau.org/4-simple-ways-to-speed-up-wordpress/

  • Digg
  • Technorati
  • del.icio.us
  • StumbleUpon
  • TwitThis
  • Sphinn
  • Facebook
  • LinkedIn
  • Google
  • YahooMyWeb
  • description
  • MisterWong
  • Live
  • 我挖网
  • QQ书签
  • 收客网
  • 百度搜藏
  • DigLog
  • 饭否
  • 365Key网摘
  • POCO网摘
  • 新浪ViVi

Here's A Few More Related Posts

RSS feed | Trackback URI

2 Comments »

Comment by dog
2008-08-06 20:30:44
MyAvatars 0.2

基本都说到点上了, 这个适用于使用虚拟主机的用过户。

Comment by David Lau
2008-08-08 14:52:40
MyAvatars 0.2

嗯,我修改主题的时候,就老是喜欢在代码中加空白,这样读起来方便。

 
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.