wordpress后台加载速度异常缓慢排查记录

2020-02-1722:21:20来源:歉信君 评论 1,313 views

原因在于在function.php函数中加入了下面的代码导致了缓慢:

//停用版本更新通知
remove_action('load-update-core.php', 'wp_update_themes');
add_filter('pre_site_transient_update_themes', create_function('$a', "return null;"));
//停用插件更新通知
remove_action('load-update-core.php', 'wp_update_plugins');
add_filter('pre_site_transient_update_plugins', create_function('$a', "return null;"));
//停用主题更新通知
remove_action ('load-update-core.php', 'wp_update_themes');
add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));

首先:去掉上述代码

再一个发现了如下代码:

<link rel='stylesheet' id='colors-css'  href='/wp-admin/' type='text/css' media='all' />

它会加载当前页面作为一个CSS文件,相当于当前页面加载了2次,且用浏览器工具调试会后台输出:

Resource interpreted as Stylesheet but transferred with MIME type text/html

临时解决办法:

default-filters.php  注释掉

//去除 colors-css
//add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 );

再一个:admin-header.php ,直接把输出的CSS样式硬写入,并注释掉wp_enqueue_style。因为如果直接去掉,会把样式中的一些东西去掉,下面这些可能会被去掉
( common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,widgets,site-icon,&load%5B%5D=l10n,buttons,wp-auth-check )
所以只好硬编码写入了,这是一个临时解决办法

<title><?php echo $admin_title; ?></title>
<!--  替代:wp_enqueue_style( 'colors' ); 去除 colors-css  -->
<link rel='stylesheet' href='http://www.muyingqianyan.com/wp-admin/load-styles.php?c=1&dir=ltr&load%5B%5D=dashicons,admin-bar,common,forms,admin-menu,dashboard,list-tables,edit,revisions,media,themes,about,nav-menus,widgets,site-icon,&load%5B%5D=l10n,buttons,wp-auth-check&ver=4.7.4' type='text/css' media='all' />
<?php
//wp_enqueue_style( 'colors' );
wp_enqueue_style( 'ie' );
wp_enqueue_script('utils');
wp_enqueue_script( 'svg-painter' );

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: