发布价值信息
Wordpress、Software、VPN。。

WordPress 缓存插件 WP Rocket v2.9.9 汉化版

WordPress 静态缓存插件有很多,比如: WP Super Cache 、 Hyper Cache 、 W3 Total Cache 、当然还有今天何先生要介绍的 WP Rocket 插件。它们都各有各的特点,感兴趣的朋友可以百度一下,今天主要讲一讲 WP Rocket 的使用介绍。

产品描述

WP Rocket 自称是当前最高效也是最灵活的 WordPress 静态缓存插件。可以优化你的 JS CSS 文件结构减少多次请求达到优化速度的目的,还集成了图片延迟加载对最求极致加速的用户不错的选择,通过使用这个插件,能使得你的 WordPress 博客将显著的提速。

WordPress 缓存插件 WP Rocket v2.9.8.1 汉化版

WordPress 缓存插件 WP Rocket v2.9.8.1 汉化版

更新日志

2.9.9 (2017年3月22日更新)

  • Enhancement: Compatibility with GoDaddy Managed Hosting
  • Enhancement: Update Mobile_Detect class to recent version
  • Enhancement: Allow caching when the ao_noptimize query string is set
  • Fix: LazyLoad Iframes & Videos no longer crashes Android Facebook browser
  • Fix: CDN URL no longer applied on SVG URL by reference
  • Fix: Remove query string is now correctly applied when minification disabled on a single post
  • Fix: Imagify install button works again

2.9.8.1 (2017年3月2日更新)

  • Regression Fix: PHP Fatal error: Can’t use function return value in write context in ../inc/front/cdn.php on line 138

WP Rocket v2.9.2(2017年1月11日)

  • Enhancement: Apply CDN URL to images displayed with wp_get_attachment_image_src()
  • Enhancement: Preserve Yandex comments during HTML minification
  • Enhancement: save CloudFlare IPs in a transient to prevent calls to the CloudFlare API
  • Fix: Replace spaces in cache busting path to prevent loading issue with the cache busting files
  • Fix: Do not minify if request is a POST method to prevent JS files to be added in the footer of a not cached page
  • Fix: Check if post type is an object before purge to prevent a PHP warning
  • Fix: Correctly remove the cache busting folder when uninstalling WP Rocket
  • Fix: Force int type for CloudFlare browser cache TTL value

关于 WP Rocket 配置

我这里主要讲 web 服务器是 Nginx 的使用方法。

1、下载安装 WP Rocket (下载地址往下看),39 刀正版支持,诸位老板少抽几包烟,尽量支持官方。

2、添加rewite规则到vhost配置文件中。目的就是让web服务器节省在请求动态文件,直接读取生成的静态文件。

###################################################################################################
# Rocket-Nginx
#
# Rocket-Nginx is a NGINX configuration to speedup your WordPress
# website with the cache plugin WP-Rocket (http://wp-rocket.me)
#
# Author: Maxime Jobin
# URL: https://github.com/maximejobin/rocket-nginx
#
# Tested with WP-Rocket version: 2.8.11
# Tested with NGINX: 1.11.3 (mainline)
#
# Version 1.2
#
###################################################################################################

# Add debug information into header
set $rocket_debug 0;

# HTTP Strict Transport Security (to overwrite default)
set $rocket_hsts_value "";

# WP-Content directory (leave as is if you did not alter WordPress' default value)
set $rocket_wpcontent_directory "$document_root/wp-content";

# WP-Content URL (leave as is if you did not alter WordPress' default value)
set $rocket_wpcontent_url "/wp-content";

###################################################################################################
# Do not alter theses values
#
set $rocket_bypass 1;				# Should NGINX bypass WordPress and call cache file directly ?
set $rocket_encryption "";			# Is GZIP accepted by client ?
set $rocket_file "";				# Filename to use
set $rocket_is_bypassed "No";		# Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Bypass
set $rocket_reason "";				# Reason why cache file was not used. If cache file is used, what file was used
set $rocket_https_prefix "";		# HTTPS prefix to use when cached files are using HTTPS
set $rocket_hsts 0;					# Is HSTS is off (0) by default. Will be turned on (1) if request is HTTPS

# HSTS Default value : 1 year, include subdomains.
set $rocket_hsts_value_default "max-age=31536000; includeSubDomains";

###################################################################################################
# PAGE CACHE
#

# Is GZIP accepted by client ?
if ($http_accept_encoding ~ gzip) {
	set $rocket_encryption "_gzip";
}

# Is SSL request ?
if ($https = "on") {
	set $rocket_https_prefix "-https";
	set $rocket_hsts 1;
}

# If HSTS value is not set, use default value
if ($rocket_hsts_value = "") {
	set $rocket_hsts_value "$rocket_hsts_value_default";
}

# If HSTS is disabled, unset HSTS set for Rocket-Nginx configuration
if ($rocket_hsts = "0") {
	set $rocket_hsts_value "";
}

# File/URL to return IF we must bypass WordPress
# index-mobile.html
# index-mobile-https.html
set $rocket_end "/cache/wp-rocket/$http_host/$request_uri/index$rocket_https_prefix.html$rocket_encryption";
set $rocket_url "$rocket_wpcontent_url$rocket_end";
set $rocket_file "$rocket_wpcontent_directory$rocket_end";
set $rocket_mobile_detection "$rocket_wpcontent_directory/cache/wp-rocket/$http_host/$request_uri/.mobile-active";


# Do not bypass if it's a POST request
if ($request_method = POST) {
	set $rocket_bypass 0;
	set $rocket_reason "POST request";
}

# Do not bypass if arguments are found (e.g. ?page=2)
if ($is_args) {
	set $rocket_bypass 0;
	set $rocket_reason "Arguments found";
}

# Do not bypass if the site is in maintenance mode
if (-f "$document_root/.maintenance") {
	set $rocket_bypass 0;
	set $rocket_reason "Maintenance mode";
}

# Do not bypass if one of those cookie if found
# wordpress_logged_in_[hash] : When a user is logged in, this cookie is created (we'd rather let WP-Rocket handle that)
# wp-postpass_[hash] : When a protected post requires a password, this cookie is created.
if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle|comment_author_|comment_author_email_)") {
	set $rocket_bypass 0;
	set $rocket_reason "Cookie";
}

if (-f "$rocket_mobile_detection") {
	set $rocket_bypass 0;
	set $rocket_reason "Specific mobile cache activated";	
}

# Do not bypass if the cached file does not exist
if (!-f "$rocket_file") {
	set $rocket_bypass 0;
	set $rocket_reason "File not cached";
}

# If the bypass token is still on, let's bypass WordPress with the cached URL
if ($rocket_bypass = 1) {
	set $rocket_is_bypassed "Yes";
	set $rocket_reason "$rocket_url";
}

# Clear variables if debug is not needed
if ($rocket_debug = 0) {
	set $rocket_reason "";
	set $rocket_file "";
}

# If the bypass token is still on, rewrite according to the file linked to the request
if ($rocket_bypass = 1) {
	rewrite .* "$rocket_url" last;
}

# Add header to HTML cached files
location ~ /wp-content/cache/wp-rocket/.*html$ {
	add_header Vary "Accept-Encoding, Cookie";
	add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
	add_header X-Rocket-Nginx-Reason $rocket_reason;
	add_header X-Rocket-Nginx-File $rocket_file;
	add_header Strict-Transport-Security "$rocket_hsts_value";
	expires 30d;
	
	#!# HEADER_HTTP #!#
	#!# HEADER_NON_GZIP #!#
}

# Do not gzip cached files that are already gzipped
location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
	gzip off;
	types {}
	default_type text/html;
	add_header Content-Encoding gzip;
	add_header Vary "Accept-Encoding, Cookie";
	add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
	add_header X-Rocket-Nginx-Reason $rocket_reason;
	add_header X-Rocket-Nginx-File $rocket_file;
	add_header Strict-Transport-Security "$rocket_hsts_value";
	expires 30d;
	
	#!# HEADER_HTTP #!#
	#!# HEADER_GZIP #!#
}

# Debug header (when file is not cached)
add_header X-Rocket-Nginx-Bypass $rocket_is_bypassed;
add_header X-Rocket-Nginx-Reason $rocket_reason;
add_header X-Rocket-Nginx-File $rocket_file;

# No HSTS header added here. We suppose it's correctly added in the site configuration


###################################################################################################
# BROWSER CSS CACHE
#
location ~* \.css$ {
	gzip_vary on;
	expires 30d;
	
	#!# HEADER_CSS #!#
}


###################################################################################################
# BROWSER JS CACHE
#
location ~* \.js$ {
	gzip_vary on;
	expires 30d;
	
	#!# HEADER_JS #!#
}


###################################################################################################
# BROWSER MEDIA CACHE
#
location ~* \.(ico|gif|jpe?g|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
	expires 30d;
	
	#!# HEADER_MEDIAS #!#
}

以上代码复制保存为 rocket.conf 文件上传到你的 nginx/conf 目录中,然后我们只要在我们的vhsot文件中引入即可。

# BEGIN WP rocket
include /usr/local/nginx/conf/rocket.conf;
# END WP rocket

然后 Nginx restart 重启一下使文件生效。按照如上配置好之后,查看网站源码,源码最底部就会出现安装成功后的提示如下:

<!-- This website is like a Rocket, isn't it ? Performance optimized by WP Rocket. Learn more: http://wp-rocket.me - Debug: cached@1458565320 -->

能看到此信息,就说明完事ok了。

PS:当然何先生并没有使用这款插件,而是选择了 WP Super Cache 这款插件,为什么呢?因为这款插件似乎评论者填写评论信息之后再访问网页就不会再访问缓存内容了,而 WP Super Cache 确有这个设置,我是一个强迫症患者,我需要所有人看到的都是缓存,这也是我没有使用这款插件的原因,当然这款插件的优化速度是比 WP Super Cache 要快很多的,看各自舍取吧

赞(0) 打赏本站

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

×
打赏作者
未经允许不得转载:何先生 » WordPress 缓存插件 WP Rocket v2.9.9 汉化版
分享到: 更多 (0)

Comments 14

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. 沙发

    我这不就回来了么!

    iEdon
    2
    2年前 (2017-02-15)回复 Google Chrome 55.0.2883.87| Windows 10 x64| IP数据库错误或不存在
    • @iEdon 夜猫子。。我居然才在你的博客留言过两次,前天翻了半天,还是你能坚持啊,域名网名都没换。

      何先生
      管理员
      2年前 (2017-02-15)回复 Google Chrome 56.0.2924.87| Windows 10 x64| IP数据库错误或不存在
      • @何先生 你一次次的删QQ好友 当然会丢失了 TAT

        iEdon
        2
        2年前 (2017-02-15)回复 Google Chrome 55.0.2883.87| Windows 10 x64| IP数据库错误或不存在
        • @iEdon 我也不知道怎么就搞没了,晕

          何先生
          管理员
          2年前 (2017-02-16)回复 Google Chrome 56.0.2924.87| Windows 10 x64| IP数据库错误或不存在
  2. 板凳

    不错,缓存还是挺有必要的。

    何湘辉博客
    1
    2年前 (2017-02-15)回复 Firefox 51.0| Windows 7 x64| IP数据库错误或不存在
  3. 地板

    :mrgreen: 我也是用WP Super Cache缓存插件,这款插件听说很厉害,不过我也懒得折腾了

    boke112导航
    2
    2年前 (2017-03-11)回复 Google Chrome 45.0.2454.101| Windows 7 x64| IP数据库错误或不存在
  4. 4楼

    其实缓存原理基本都是差不多的额 这个插件附加功能还是很多的 估计就是很多人用的原因吧

    BanYuner
    2
    2年前 (2017-03-29)回复 Google Chrome 57.0.2987.110| Windows 10 x64| IP数据库错误或不存在
  5. 5楼

    求教vhsot文件具体是指哪个,我没有找到,神奇了。只找到了vhost文件夹,文件夹里倒是有两个.conf文件

    完颜小铭
    0
    1年前 (2017-08-11)回复 Firefox 54.0| Windows 10 x64| IP数据库错误或不存在
  6. 6楼

    贵站打开速度确实不错。

    搬瓦工
    0
    1年前 (2017-08-16)回复 Firefox 54.0| Windows 7 x64| IP数据库错误或不存在
  7. 7楼

    不错,多谢博主!

    worthpin
    0
    1年前 (2017-08-29)回复 Google Chrome 60.0.3112.101| Windows 7 x64| IP数据库错误或不存在
  8. 8楼

    已经下载了,等等试试

    蛋糕
    1
    1年前 (2017-10-13)回复 Google Chrome 55.0.2883.87| Windows 7 x64| IP数据库错误或不存在
    • @蛋糕 何S,预先载入–需要开启吗?

      蛋糕
      1
      1年前 (2017-10-25)回复 Google Chrome 55.0.2883.87| Windows 7 x64| IP数据库错误或不存在
      • @蛋糕 这个可以开启,也可以不开启,提升不是很大,微乎其微

        何先生
        管理员
        1年前 (2017-10-25)回复 Google Chrome 62.0.3202.62| Windows 10 x64| IP数据库错误或不存在
  9. 9楼

    在iis8.5怎么也米缓存,不知道是哪些原因

    webkv
    0
    2个月前 (09-02)回复 Google Chrome 68.0.3440.106| Windows 8.1 x64| IP数据库错误或不存在

何先生的博客 专注分享 更优质

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏