2016-04-29 78 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; 
    } 

    ... 

}