Skip to content

Commit 1b78b00

Browse files
fixed prefetching bug
1 parent 6aadd49 commit 1b78b00

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

admin/prefetch-settings.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function cache_everything_display_prefetch_settings() {
1616

1717
function cache_everything_set_default_prefetch_settings() {
1818
// Force update to default settings
19-
update_option('cache_everything_prefetch_enabled', 'no'); // Default disabled
19+
update_option('cache_everything_prefetch_enabled', '0'); // Default disabled
2020

2121
// Define and force update default patterns
2222
$default_patterns = [
@@ -103,9 +103,11 @@ function cache_everything_prefetch_settings_section_callback() {
103103
}
104104

105105
function cache_everything_prefetch_enable_callback() {
106-
$option = get_option('cache_everything_prefetch_enabled');
107-
$checked = ($option === 'yes') ? 'checked' : '';
108-
echo '<input type="checkbox" id="cache_everything_prefetch_enable" name="cache_everything_prefetch_enabled" value="yes" ' . $checked . '>';
106+
$option = get_option('cache_everything_prefetch_enabled', '0'); // Default to '0'
107+
$checked = ($option === '1') ? 'checked' : '';
108+
// Add a hidden input field with the same name and a value of '0'
109+
echo '<input type="hidden" name="cache_everything_prefetch_enabled" value="0">';
110+
echo '<input type="checkbox" id="cache_everything_prefetch_enable" name="cache_everything_prefetch_enabled" value="1" ' . $checked . '>';
109111
echo '<label for="cache_everything_prefetch_enable">Activate Prefetching</label>';
110112
}
111113

cache-everything.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* Plugin Name: Cache Everything
44
* Plugin URI: https://github.com/AsyncAlchemist
55
* Description: A simple plugin to cache everything in Wordpress.
6-
* Version: 0.24
6+
* Version: 0.25
77
* Author: Taylor Selden
88
* Author URI: https://github.com/AsyncAlchemist
99
*/
1010
define('CACHE_EVERYTHING_JS_URL', 'wp-content/plugins/cache-everything/js');
1111
define('CACHE_EVERYTHING_CSS_URL', 'wp-content/plugins/cache-everything/css');
12-
define('CACHE_EVERYTHING_VERSION', '0.24');
12+
define('CACHE_EVERYTHING_VERSION', '0.25');
1313

1414
require_once(plugin_dir_path(__FILE__) . 'handle-js-request.php');
1515
require_once(plugin_dir_path(__FILE__) . 'handle-css-request.php');
@@ -90,7 +90,7 @@ function cache_everything_enqueue_scripts() {
9090
$debug_mode = get_option('cache_everything_debug_mode', '0'); // Default to '0' if not set
9191

9292
// Retrieve the prefetching options
93-
$prefetch_enabled = get_option('cache_everything_prefetch_enable', '0');
93+
$prefetch_enabled = get_option('cache_everything_prefetch_enabled', '0');
9494
$prefetch_patterns = get_option('cache_everything_prefetch_patterns', array());
9595

9696
$patterns_starts_with = array();

readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ To customize the plugin's behavior, navigate to the WordPress admin panel and ac
3131
- **Cache Expiration Times**: Set the maximum age for cached content and configure the stale-while-revalidate behavior to ensure content freshness.
3232
- **Debug Mode**: Enable or disable debug mode to assist in troubleshooting with detailed console logs.
3333

34+
### Cloudflare Setup
35+
36+
The last part of the set-up is to add two cloudflare cache rules.
37+
38+
1. Rule Name: Do Not Cache WP-ADMIN
39+
- Field: URI Path
40+
- Operator: Contains
41+
- Value: wp-admin
42+
- Then:
43+
- Cache eligibility: Bypass cache
44+
- Browser TTL: Bypass cache
45+
2. Rule 2: Cache HTML
46+
- Field: Hostname
47+
- Operator: Equals
48+
- Value: Your website (i.e. www.example.com)
49+
- Then:
50+
- Cache eligibility: Eligible for cache
51+
- No need to set the Browser TTL (or any other setting)
52+
3453
## Development
3554

3655
To add new features or modify existing ones, edit the PHP files in the plugin directory and the JavaScript files in the `public/js` directory.

0 commit comments

Comments
 (0)