Skip to content

Commit 2b23b11

Browse files
committed
Enhance WP Rocket configuration file with comprehensive documentation and updated options. Added requirements for WordPress and PHP versions, improved comments for clarity, and included new filters for mobile caching, CSS/JS minification, and preloading settings.
1 parent 199c807 commit 2b23b11

1 file changed

Lines changed: 128 additions & 16 deletions

File tree

default-wp-rocket.php

Lines changed: 128 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,152 @@
11
<?php
22
/**
3-
* Plugin Name: Be API - WP Rocket config
4-
* Description: Default option for WP Rocket
5-
* Version: 1.0
6-
* Author: BeAPI
7-
* Author URI: http://beapi.fr/
3+
* Plugin Name: Be API - WP Rocket config
4+
* Plugin URI: https://github.com/BeAPI/bea-plugin-defaults
5+
* Description: Default options for WP Rocket (caching, minification, preload, etc.).
6+
* Version: 1.0.0
7+
* Requires at least: 5.9
8+
* Requires PHP: 7.4
9+
* Author: BeAPI
10+
* Author URI: https://beapi.fr
11+
* License: GPL-2.0-or-later
12+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
13+
* Text Domain: bea-plugin-defaults
14+
*
15+
* =============================================================================
16+
* >>> REMINDER: This file MUST be customized per project. <<<
17+
* =============================================================================
18+
* Review and adjust every option below (enable/disable, comment/uncomment)
19+
* according to the project's hosting, cache layer, and performance requirements.
20+
* =============================================================================
21+
*
22+
* All options below use the pre_get_rocket_option_{option_name} filter system.
23+
*
24+
* @see https://docs.wp-rocket.me/article/1564-list-of-pre-get-rocket-option-filters
25+
* @see https://docs.wp-rocket.me/article/1677-how-to-programmatically-configure-wp-rocket-options
826
*/
927

1028
namespace BEAPI\Plugin_Defaults\WP_Rocket;
1129

12-
// Enable caching for mobile devices
30+
/**
31+
* Enable mobile cache (WP Rocket will apply cache rules for mobile user agents).
32+
* Used together with do_caching_mobile_files below.
33+
*
34+
* @see https://docs.wp-rocket.me/article/708-mobile-cache
35+
* @see https://github.com/wp-media/wp-rocket-helpers/blob/master/cache/wp-rocket-customize-mobile-cache/wp-rocket-customize-mobile-cache.php
36+
*/
1337
add_filter( 'pre_get_rocket_option_cache_mobile', '__return_true' );
1438

15-
// Load async css
39+
/**
40+
* Enable separate cache files for mobile (split cache by device).
41+
* WP Rocket serves a distinct cache for mobile user agents; enables above-the-fold,
42+
* LRC and preconnect optimizations for mobile. Use more storage.
43+
*/
44+
add_filter( 'pre_get_rocket_option_do_caching_mobile_files', '__return_true' );
45+
46+
/**
47+
* Load CSS files asynchronously to prevent render-blocking.
48+
* Improves LCP; critical CSS can be inlined while other styles load async.
49+
*
50+
* @see https://docs.wp-rocket.me/article/1266-load-css-asynchronously
51+
*/
1652
add_filter( 'pre_get_rocket_option_async_css', '__return_true' );
1753

18-
// Minifying css files
54+
/**
55+
* Disable Remove Unused CSS (no automatic removal of unused CSS from stylesheets).
56+
* If you enable this option: it only works for public sites (crawlable by WP Rocket),
57+
* read the WP Rocket documentation carefully, enable it together with preload (sitemap
58+
* or manual) so the critical CSS is generated correctly, and disable async CSS
59+
* (pre_get_rocket_option_async_css) when using this feature.
60+
*
61+
* @see https://docs.wp-rocket.me/article/1529-remove-unused-css
62+
*/
63+
add_filter( 'pre_get_rocket_option_remove_unused_css', '__return_zero' );
64+
65+
/**
66+
* Minify CSS files to reduce size and number of requests.
67+
*/
1968
add_filter( 'pre_get_rocket_option_minify_css', '__return_true' );
2069

21-
// Minifying js files
70+
/**
71+
* Minify JavaScript files to reduce size and parse time.
72+
*/
2273
add_filter( 'pre_get_rocket_option_minify_js', '__return_true' );
2374

24-
// Defer all js
75+
/**
76+
* Defer parsing of JavaScript so it does not block initial page render.
77+
* Scripts load after the page is interactive; exclude any that must run immediately if needed.
78+
*
79+
* @see https://docs.wp-rocket.me/article/976-exclude-files-from-defer-js
80+
*/
2581
add_filter( 'pre_get_rocket_option_defer_all_js', '__return_true' );
2682

27-
// Optimizing css loading by default
83+
/**
84+
* Optimize CSS delivery (e.g. remove unused CSS / critical CSS).
85+
* Reduces render-blocking and improves First Contentful Paint.
86+
*/
2887
add_filter( 'pre_get_rocket_option_optimize_css_delivery', '__return_true' );
2988

30-
// Activate preloading
31-
add_filter( 'pre_get_rocket_option_sitemap_preload_url_crawl', '__return_true' );
89+
/**
90+
* Disable sitemap-based cache preloading (WP Rocket will NOT crawl sitemap URLs to warm cache).
91+
* Key pages will NOT be cached via sitemap preload after clearing or on a schedule.
92+
*/
93+
add_filter( 'pre_get_rocket_option_sitemap_preload_url_crawl', '__return_zero' );
94+
95+
/**
96+
* Disable manual cache preload via WP Rocket admin.
97+
*
98+
* For advanced or configurable preloading, consider the WP Rocket Smart Preload helper:
99+
* @see https://github.com/wp-media/wp-rocket-smart-preload
100+
*/
101+
add_filter( 'pre_get_rocket_option_manual_preload', '__return_zero' );
32102

33-
// Enable preloading of links
103+
/**
104+
* Enable preload for links (prefetch on hover or in viewport).
105+
* Speeds up navigation when users click preloaded links.
106+
*/
34107
add_filter( 'pre_get_rocket_option_preload_links', '__return_true' );
35108

36-
// Enable control Heartbeat
109+
/**
110+
* Enable Heartbeat API control (throttle or disable in admin/frontend).
111+
* Reduces CPU and requests from the WordPress Heartbeat.
112+
*/
37113
add_filter( 'pre_get_rocket_option_control_heartbeat', '__return_true' );
38114

39-
// Disable the wprocket 'wp_cache' constant in wp_config to prevent fatal error due to pre-existing constant
115+
/**
116+
* Prevent WP Rocket from writing define( 'WP_CACHE', true ) into wp-config.php.
117+
* Use when WP_CACHE is already defined (e.g. Bedrock, custom config) to avoid fatal errors.
118+
*
119+
* @see https://docs.wp-rocket.me/article/958-how-to-use-wp-rocket-with-bedrock-wordpress-boilerplate
120+
* @see https://docs.wp-rocket.me/article/1518-wpcache-is-set-to-false
121+
*/
40122
add_filter( 'rocket_set_wp_cache_constant', '__return_false' );
123+
124+
/**
125+
* Completely disable page caching in WP Rocket.
126+
*
127+
* Use this if full page caching is already handled by a reverse proxy such as Varnish, Cloudflare, or Batcache.
128+
* Prevents WP Rocket from generating static HTML cache files to avoid duplicate or conflicting cache layers.
129+
*
130+
* @see https://docs.wp-rocket.me/article/61-disable-page-caching
131+
*
132+
* Uncomment the line below to activate.
133+
* add_filter( 'do_rocket_generate_caching_files', '__return_false' );
134+
*/
135+
136+
/*
137+
* Completely disable WP Rocket writing to advanced-cache.php
138+
*
139+
* @see: https://github.com/wp-media/wp-rocket/issues/4707
140+
*
141+
* Uncomment the line below to activate.
142+
* add_filter( 'rocket_generate_advanced_cache_file', '__return_false' );
143+
*/
144+
145+
/*
146+
* Completely disable WP Rocket writing to .htaccess (e.g. Nginx, or .htaccess managed elsewhere).
147+
*
148+
* @see: https://github.com/wp-media/wp-rocket-helpers/blob/master/htaccess/wp-rocket-no-htaccess/wp-rocket-no-htaccess.php
149+
*
150+
* Uncomment the line below to activate.
151+
* add_filter( 'rocket_disable_htaccess', '__return_true' );
152+
*/

0 commit comments

Comments
 (0)