2016-04-29 75 views
1

我一直在为我为WordPress构建的自定义主题存在问题。等待时间在20秒左右。WordPress网站上的漫长等待时间

我尝试没有成功如下:

  • 禁用所有的插件。
  • 从主题中删除了包括WordPress的所有脚本。
  • 切换到不同的主机。

任何人都知道可能是什么问题?我知道Firebug的等待时间意味着等待服务器响应,但无法找出问题所在。

Firebug showing long waiting time for page request

+0

哪些文件正在服用较长时间来加载? –

+0

@PedroLobito所有的网站页面 – Jason

+0

您使用共享的虚拟主机或虚拟主机? –

回答

2

你应该将这些特定的规则有一些运气:

  1. 使用W3的总缓存插件(这是最好的在其利基)或任何其他缓存插件。
  2. 如果您的主题有一些,请使用优化的图像。
  3. 压缩所有的CSS和JavaScript文件。
  4. 使用延迟加载插件可以快速加载文本,但会在后台加载图像。
  5. 请确保您没有使用任何减缓大多数情况下页面加载时间的框架。
  6. 使用内容交付网络(CDN)。
  7. 将一个Expires标题添加到静态资源。
  8. 尽可能快地使用静态HTML。
  9. 确保主题中没有不必要的额外代码或文件。
  10. 应用所有这些步骤,并进一步阅读有关页面优化技术,以获得良好和长期的结果。
2

听起来像这是一个PHP问题。你有没有尝试绕过PHP来看看这是否是事实?为了测试这个,我建议安装一个像Cache Enabler这样的缓存插件,然后在原始服务器上实现advanced snippet,以便在检索由该插件生成的缓存HTML时绕过PHP。

为Apache

高级片断:

# Start Cache Enabler 
<IfModule mod_rewrite.c> 
RewriteEngine On 

<IfModule mod_mime.c> 
# webp HTML file 
RewriteCond %{REQUEST_URI} /$ 
RewriteCond %{REQUEST_URI} !^/wp-admin/.* 
RewriteCond %{REQUEST_METHOD} !=POST 
RewriteCond %{QUERY_STRING} ="" 
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_ 
RewriteCond %{HTTP:Accept-Encoding} gzip 
RewriteCond %{HTTP:Accept} image/webp 
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index-webp.html.gz -f 
RewriteRule ^(.*) /wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index-webp.html.gz [L] 

# gzip HTML file 
RewriteCond %{REQUEST_URI} /$ 
RewriteCond %{REQUEST_URI} !^/wp-admin/.* 
RewriteCond %{REQUEST_METHOD} !=POST 
RewriteCond %{QUERY_STRING} ="" 
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_ 
RewriteCond %{HTTP:Accept-Encoding} gzip 
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index.html.gz -f 
RewriteRule ^(.*) /wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index.html.gz [L] 

AddType text/html .gz 
AddEncoding gzip .gz 
</IfModule> 

# default HTML file 
RewriteCond %{REQUEST_URI} /$ 
RewriteCond %{REQUEST_URI} !^/wp-admin/.* 
RewriteCond %{REQUEST_METHOD} !=POST 
RewriteCond %{QUERY_STRING} ="" 
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_ 
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index.html -f 
RewriteRule ^(.*) /wp-content/cache/cache-enabler/%{HTTP_HOST}%{REQUEST_URI}index.html [L] 
</IfModule> 
# End Cache Enabler 

Nginx的:

server { 

    set $cache_uri $request_uri; 

    # bypass cache if POST requests or URLs with a query string 
    if ($request_method = POST) { 
     set $cache_uri 'nullcache'; 
    } 
    if ($query_string != "") { 
     set $cache_uri 'nullcache'; 
    } 

    # bypass cache if URLs containing the following strings 
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { 
     set $cache_uri 'nullcache'; 
    } 

    # bypass cache if the cookies containing the following strings 
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { 
     set $cache_uri 'nullcache'; 
    } 

    # custom sub directory e.g. /blog 
    set $custom_subdir ''; 

    # default html file 
    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html'; 

    # webp html file 
    if ($http_accept ~* "image/webp") { 
     set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html'; 
    } 

    location/{ 
     gzip_static on; # this directive is not required but recommended 
     try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args; 
    } 

    ... 

}