Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Apache Optimization panel and features, edited Pro Features label #260

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b0629bf
Added Apache Optimization panel and features, edited Pro Features label
renzms Jun 21, 2016
1439ccc
Removed IfModule section
renzms Jun 21, 2016
9adc732
Merge branch '000000-dev' into feature/554-764-765-788
renzms Jun 24, 2016
04d4212
Added new options to .htaccess rules
renzms Jun 24, 2016
ba8eee4
Merge branch '000000-dev' into feature/554-764-765-788
raamdev Jun 25, 2016
0e0fceb
Set ExpiresDefault to 1 week.
raamdev Jun 25, 2016
603ca8c
Improve Apache Optimizations panel.
raamdev Jun 25, 2016
0bb51b8
Use redirect links in Apache Optimizations panel.
raamdev Jun 25, 2016
4f0671a
Clarify how Client-Side Caching differs from Leverage Browser Caching
raamdev Jun 25, 2016
8d7e787
Rename 'permalink structure' to 'enforce canonical urls' for clarity
raamdev Jun 25, 2016
b8e11d9
Remove `htaccess_gzip_enable` from Pro-only option keys; Lite has this
raamdev Jun 25, 2016
ed1484d
Rename 'htaccess client side cache' to 'htaccess browser caching'
raamdev Jun 25, 2016
f4d6dc1
Remove gzip-htaccess.txt; no longer used.
raamdev Jun 25, 2016
f8a3f19
Refactor 'browser caching' to 'client side caching'
raamdev Jun 25, 2016
dde3a0d
Only show 'Enforce Canonical URLs' panel when fancy Permalinks enabled
raamdev Jun 25, 2016
734609c
Rename BrowserUtils.php to ClientSideUtils.php
raamdev Jun 25, 2016
a447236
Rename 'htaccess client side cache' to 'htaccess browser caching'
raamdev Jun 27, 2016
656098f
Refactor 'browser caching' to 'client side caching'
raamdev Jun 27, 2016
72cfa46
Improve comments and spacing in htaccess templates
raamdev Jun 27, 2016
4627194
Add htaccess Access-Control-Allow-Origin option for Static CDN Filters
raamdev Jun 27, 2016
12366d6
Improve notice recommending that Access-Control-Allow-Origin be enabled
raamdev Jun 27, 2016
9d076ab
Gain control over htaccess tweaks order
raamdev Jun 27, 2016
4ec5801
Fix bug where updating Permalinks does not refresh htaccess code
raamdev Jun 27, 2016
bb3bae0
Fix bug where disabling Static CDN Filters did not update htaccess
raamdev Jun 27, 2016
4e29d12
Improve description for htaccess 'Access-Control-Allow-Origin' option.
raamdev Jun 27, 2016
02d8fc3
Improve Apache Optimizations description and option headers
raamdev Jun 27, 2016
83cbbb1
Add Pro Preview note to Apache Optimization in Lite version
raamdev Jun 28, 2016
b59bf78
Fix upgrade bug w/ COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE undefined warning
raamdev Jun 28, 2016
e142c58
Show upgrade notice about new Apache Optimizations panel
raamdev Jun 28, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/includes/classes/AdvCacheBackCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,23 @@ public static function zenCacheConstants()

unset($_constant, $_value, $_global_ns); // Housekeeping.
}

/**
* Back compat. with `COMET_CACHE_ALLOW_BROWSER_CACHE` constants.
*
* @since 16xxxx Renaming COMET_CACHE_ALLOW_BROWSER_CACHE to COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE
*/
public static function browserCacheConstant()
{
$_global_ns = mb_strtoupper(GLOBAL_NS);

if (!($constants = get_defined_constants(true)) || empty($constants['user'])) {
Copy link
Contributor

@jaswrks jaswrks Jun 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. However, you can optimize this further by ditching the section that collects user-defined constants; i.e., get rid of get_defined_constants() and instead of the in_array() check, just use if (defined('COMET_CACHE_ALLOW_BROWSER_CACHE')) {

The reason is because this back compat. routine is only looking for one specific constant and not any that have a special prefix like the other method does. So it's easier, and simpler will be equal to faster.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaswsinc Done. 656098f Thanks! :-)

return; // Nothing to do; i.e. no user-defined constants.
}
if (in_array('COMET_CACHE_ALLOW_BROWSER_CACHE', $constants['user'])) {
if (!defined($_global_ns.'_ALLOW_CLIENT_SIDE_CACHE')) {
define($_global_ns.'_ALLOW_CLIENT_SIDE_CACHE', $constants['user']['COMET_CACHE_ALLOW_BROWSER_CACHE']);
}
}
}
}
2 changes: 1 addition & 1 deletion src/includes/classes/AdvancedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AdvancedCache extends AbsBaseAp
/*[.build.php-auto-generate-use-Traits]*/
use Traits\Ac\AbortUtils;
use Traits\Ac\AcPluginUtils;
use Traits\Ac\BrowserUtils;
use Traits\Ac\ClientSideUtils;
use Traits\Ac\HtmlCUtils;
use Traits\Ac\NcDebugUtils;
use Traits\Ac\ObUtils;
Expand Down
6 changes: 3 additions & 3 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ public function __construct()
echo ' <p>'.__('<strong>This option is NOT the same as "Leverage Browser Caching"</strong>, which refers to the caching of static resources in the browser (e.g., images, CSS, JS). This Client-Side Cache option is different in that it controls the caching of <em>page content</em> in the browser, i.e., the caching of HTML content generated by PHP itself, which is generally NOT static. If you\'re looking to Leverage Browser Caching for static resources (highly recommended), see the <strong>Apache Optimizations</strong> panel below.', SLUG_TD).'</p>'."\n";
echo ' <p>'.sprintf(__('%1$s handles content delivery through its ability to communicate with a browser using PHP. If you allow a browser to (cache) the caching system itself, you are momentarily losing some control; and this can have a negative impact on users that see more than one version of your site; e.g., one version while logged-in, and another while NOT logged-in. For instance, a user may log out of your site, but upon logging out they report seeing pages on the site which indicate they are STILL logged in (even though they\'re not — that\'s bad). This can happen if you allow a client-side cache, because their browser may cache web pages they visited while logged into your site which persist even after logging out. Sending no-cache headers will work to prevent this issue.', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <p>'.__('All of that being said, if all you care about is blazing fast speed and users don\'t log in/out of your site (only you do); you can safely set this to <code>Yes</code> (recommended in this case). Allowing a client-side browser cache will improve speed and reduce outgoing bandwidth when this option is feasible.', SLUG_TD).'</p>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][allow_browser_cache]" data-toggle="enable-disable" data-target=".-client-side-cache-options">'."\n";
echo ' <option value="0"'.selected($this->plugin->options['allow_browser_cache'], '0', false).'>'.__('No, prevent a client-side browser cache of dynamic page content (safest option).', SLUG_TD).'</option>'."\n";
echo ' <option value="1"'.selected($this->plugin->options['allow_browser_cache'], '1', false).'>'.__('Yes, I will allow a client-side browser cache of pages on the site.', SLUG_TD).'</option>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][allow_client_side_cache]" data-toggle="enable-disable" data-target=".-client-side-cache-options">'."\n";
echo ' <option value="0"'.selected($this->plugin->options['allow_client_side_cache'], '0', false).'>'.__('No, prevent a client-side browser cache of dynamic page content (safest option).', SLUG_TD).'</option>'."\n";
echo ' <option value="1"'.selected($this->plugin->options['allow_client_side_cache'], '1', false).'>'.__('Yes, I will allow a client-side browser cache of pages on the site.', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' <p class="info">'.__('<strong>Tip:</strong> Setting this to <code>No</code> is highly recommended when running a membership plugin like <a href="http://wordpress.org/plugins/s2member/" target="_blank">s2Member</a> (as one example). In fact, many plugins like s2Member will send <a href="http://codex.wordpress.org/Function_Reference/nocache_headers" target="_blank">nocache_headers()</a> on their own, so your configuration here will likely be overwritten when you run such plugins (which is better anyway). In short, if you run a membership plugin, you should NOT allow a client-side browser cache.', SLUG_TD).'</p>'."\n";
echo ' <p class="info">'.__('<strong>Tip:</strong> Setting this to <code>No</code> will NOT impact static content; e.g., CSS, JS, images, or other media. This setting pertains only to dynamic PHP scripts which produce content generated by WordPress.', SLUG_TD).'</p>'."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public function setup()

/* Misc. cache behaviors. */

'allow_browser_cache' => '0', // `0|1`.
'allow_client_side_cache' => '0', // `0|1`.
'when_logged_in' => '0', // `0|1|postload`.
'get_requests' => '0', // `0|1`.
'feeds_enable' => '0', // `0|1`.
Expand Down
8 changes: 8 additions & 0 deletions src/includes/classes/VsUpgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,21 @@ protected function fromLte160227()

/**
* Before we changed the Auto-Cache Engine requirements check to include cURL (notice name changed)
* and before we renamed the `allow_browser_cache` option to `allow_client_side_cache`.
*
* @since 16xxxx
*/
protected function fromLte160521()
{
if (version_compare($this->prev_version, '160521', '<=')) {
$this->plugin->dismissMainNotice('allow_url_fopen_disabled');

if (is_array($existing_options = get_site_option(GLOBAL_NS.'_options'))) {
if (isset($existing_options['allow_browser_cache'])) {
$this->plugin->options['allow_client_side_cache'] = $existing_options['allow_browser_cache'];
$this->plugin->updateOptions($this->plugin->options); // Save/update options.
}
}
}
}
}
5 changes: 3 additions & 2 deletions src/includes/templates/advanced-cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (defined('WP_DEBUG') && WP_DEBUG) {
}
Classes\AdvCacheBackCompat::zenCacheConstants();
Classes\AdvCacheBackCompat::zcRequestVars();
Classes\AdvCacheBackCompat::browserCacheConstant();

if (!defined('COMET_CACHE_PRO')) {
/**
Expand Down Expand Up @@ -68,7 +69,7 @@ if (!defined('COMET_CACHE_DEBUGGING_ENABLE')) {
*/
define('COMET_CACHE_DEBUGGING_ENABLE', '%%COMET_CACHE_DEBUGGING_ENABLE%%');
}
if (!defined('COMET_CACHE_ALLOW_BROWSER_CACHE')) {
if (!defined('COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE')) {
/**
* Allow browsers to cache each document?
*
Expand All @@ -79,7 +80,7 @@ if (!defined('COMET_CACHE_ALLOW_BROWSER_CACHE')) {
* @note If this is a `FALSE` (or an empty) value; Comet Cache will send no-cache headers.
* If `TRUE`, Comet Cache will NOT send no-cache headers.
*/
define('COMET_CACHE_ALLOW_BROWSER_CACHE', '%%COMET_CACHE_ALLOW_BROWSER_CACHE%%');
define('COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE', '%%COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE%%');
}
if (!defined('COMET_CACHE_GET_REQUESTS')) {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/includes/traits/Ac/BrowserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use WebSharks\CometCache\Pro\Classes;

trait BrowserUtils
trait ClientSideUtils
{
/**
* Sends no-cache headers (if applicable).
Expand All @@ -12,7 +12,7 @@ trait BrowserUtils
*/
public function maybeStopBrowserCaching()
{
switch ((bool) COMET_CACHE_ALLOW_BROWSER_CACHE) {
switch ((bool) COMET_CACHE_ALLOW_CLIENT_SIDE_CACHE) {

case true: // If global config allows, check exclusions.

Expand All @@ -24,7 +24,7 @@ public function maybeStopBrowserCaching()
} elseif (COMET_CACHE_EXCLUDE_CLIENT_SIDE_URIS && (empty($_SERVER['REQUEST_URI']) || preg_match(COMET_CACHE_EXCLUDE_CLIENT_SIDE_URIS, $_SERVER['REQUEST_URI']))) {
return $this->sendNoCacheHeaders(); // Disallow.
}
return; // Allow browser caching; default behavior in this mode.
return; // Allow client-side caching; default behavior in this mode.

case false: // Global config disallows; check inclusions.

Expand Down