很多人会吐槽wordpress运行慢,占内存,的确如此,wordpress比同类程序要耗资源多一些,我们看看wordpress启动加载了哪些文件就知道原因了。
我们看看wp-settiings.php文件:
// Attach the default filters.
require( ABSPATH . WPINC . '/default-filters.php' );
// Initialize multisite if enabled.
if ( is_multisite() ) {
require( ABSPATH . WPINC . '/ms-blogs.php' );
require( ABSPATH . WPINC . '/ms-settings.php' );
} elseif ( ! defined( 'MULTISITE' ) ) {
define( 'MULTISITE', false );
}
register_shutdown_function( 'shutdown_action_hook' );
// Stop most of WordPress from being loaded if we just want the basics.
if ( SHORTINIT )
return false;
// Load the L10n library.
require_once( ABSPATH . WPINC . '/l10n.php' );
// Run the installer if WordPress is not installed.
wp_not_installed();
// Load most of WordPress.
require( ABSPATH . WPINC . '/class-wp-walker.php' );
require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
require( ABSPATH . WPINC . '/formatting.php' );
require( ABSPATH . WPINC . '/capabilities.php' );
require( ABSPATH . WPINC . '/query.php' );
require( ABSPATH . WPINC . '/date.php' );
require( ABSPATH . WPINC . '/theme.php' );
require( ABSPATH . WPINC . '/class-wp-theme.php' );
require( ABSPATH . WPINC . '/template.php' );
require( ABSPATH . WPINC . '/user.php' );
require( ABSPATH . WPINC . '/session.php' );
require( ABSPATH . WPINC . '/meta.php' );
require( ABSPATH . WPINC . '/general-template.php' );
require( ABSPATH . WPINC . '/link-template.php' );
require( ABSPATH . WPINC . '/author-template.php' );
require( ABSPATH . WPINC . '/post.php' );
require( ABSPATH . WPINC . '/post-template.php' );
require( ABSPATH . WPINC . '/revision.php' );
require( ABSPATH . WPINC . '/post-formats.php' );
require( ABSPATH . WPINC . '/post-thumbnail-template.php' );
require( ABSPATH . WPINC . '/category.php' );
require( ABSPATH . WPINC . '/category-template.php' );
require( ABSPATH . WPINC . '/comment.php' );
require( ABSPATH . WPINC . '/comment-template.php' );
require( ABSPATH . WPINC . '/rewrite.php' );
require( ABSPATH . WPINC . '/feed.php' );
require( ABSPATH . WPINC . '/bookmark.php' );
require( ABSPATH . WPINC . '/bookmark-template.php' );
require( ABSPATH . WPINC . '/kses.php' );
require( ABSPATH . WPINC . '/cron.php' );
require( ABSPATH . WPINC . '/deprecated.php' );
require( ABSPATH . WPINC . '/script-loader.php' );
require( ABSPATH . WPINC . '/taxonomy.php' );
require( ABSPATH . WPINC . '/update.php' );
require( ABSPATH . WPINC . '/canonical.php' );
require( ABSPATH . WPINC . '/shortcodes.php' );
require( ABSPATH . WPINC . '/class-wp-embed.php' );
require( ABSPATH . WPINC . '/media.php' );
require( ABSPATH . WPINC . '/http.php' );
require( ABSPATH . WPINC . '/class-http.php' );
require( ABSPATH . WPINC . '/widgets.php' );
require( ABSPATH . WPINC . '/nav-menu.php' );
require( ABSPATH . WPINC . '/nav-menu-template.php' );
require( ABSPATH . WPINC . '/admin-bar.php' );
// Load multisite-specific files.
if ( is_multisite() ) {
require( ABSPATH . WPINC . '/ms-functions.php' );
require( ABSPATH . WPINC . '/ms-default-filters.php' );
require( ABSPATH . WPINC . '/ms-deprecated.php' );
}
wordpress在启动的时候就默认加载了这么多文件,运行过程中根据插件和主题也加载其他的文件,也许你根本没用到这些文件中的类或者方法。
如何优化wordpress的速度?
用wordpress不用缓存插件的话,那简直无法想象那速度,优化wordpress速度,一定要用缓存。
另外不要过多使用插件,特别是质量低的插件。如果是开发者,多利用wordpress自带的cache函数。
还有一点特殊情况,在国内不能访问谷歌字体和头像服务,要替换成国内的字体镜像。具体方法搜索本站。