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

Feature Request: Option to disable HTML Compression for Logged-In Users #208

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/includes/classes/MenuPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,13 @@ public function __construct()
echo ' <p><input type="text" name="'.esc_attr(GLOBAL_NS).'[saveOptions][htmlc_cache_expiration_time]" value="'.esc_attr($this->plugin->options['htmlc_cache_expiration_time']).'" /></p>'."\n";
echo ' <p class="info" style="display:block;">'.__('<strong>Tip:</strong> the value that you specify here MUST be compatible with PHP\'s <a href="http://php.net/manual/en/function.strtotime.php" target="_blank" style="text-decoration:none;"><code>strtotime()</code></a> function. Examples: <code>2 hours</code>, <code>7 days</code>, <code>6 months</code>, <code>1 year</code>.', SLUG_TD).'</p>'."\n";
echo ' <p>'.sprintf(__('<strong>Note:</strong> This does NOT impact the overall cache expiration time that you configure with %1$s. It only impacts the sub-routines provided by the HTML Compressor. In fact, this expiration time is mostly irrelevant. The HTML Compressor uses an internal checksum, and it also checks <code>filemtime()</code> before using an existing cache file. The HTML Compressor class also handles the automatic cleanup of your cache directories to keep it from growing too large over time. Therefore, unless you have VERY little disk space there is no reason to set this to a lower value (even if your site changes dynamically quite often). If anything, you might like to increase this value which could help to further reduce server load. You can <a href="https://github.com/websharks/HTML-Compressor" target="_blank">learn more here</a>. We recommend setting this value to at least double that of your overall %1$s expiration time.', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <hr />'."\n";
echo ' <h3>'.__('Enable HTML Compression for Logged-In Users?', SLUG_TD).'</h3>'."\n";
echo ' <p>'.__('Disabled by default. This setting is only applicable when caching for Logged-In Users is enabled. This should remain disabled for logged-in users because the user-specific cache has a much shorter Time To Live (TTL) which means their cache is likely to expire more quickly than a normal visitor. Rebuilding the HTML Compressor cache is time-consuming and doing it too frequently will actually slow things down for them. For example, if you\'re logged into the site as a user and you submit a form, that triggers a clearing of the cache for that user, including the HTML Compressor cache (when Logged-In User caching is enabled). Lots of little actions you take can result in a clearing of the cache. This shorter TTL is not ideal when running the HTML Compressor because it does a deep analysis of the page content and the associated resources in order to intelligently compress things. For logged-in users, it is better to skip that extra work and just cache the HTML source as-is, avoiding that extra overhead. In short, do NOT turn this on unless you know what you\'re doing.', SLUG_TD).'</p>'."\n";
echo ' <p><select name="'.esc_attr(GLOBAL_NS).'[saveOptions][htmlc_when_logged_in]">'."\n";
echo ' <option value="0"'.selected($this->plugin->options['htmlc_when_logged_in'], '0', false).'>'.__('No, disable HTML Compression for logged-in users (recommended).', SLUG_TD).'</option>'."\n";
echo ' <option value="postload"'.selected($this->plugin->options['htmlc_when_logged_in'], 'postload', false).'>'.__('Yes, enable HTML Compression for logged-in users.', SLUG_TD).'</option>'."\n";
echo ' </select></p>'."\n";
echo ' </div>'."\n";
echo ' </div>'."\n";

Expand Down
2 changes: 2 additions & 0 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function setup()
'htmlc_compress_css_code',
'htmlc_compress_js_code',
'htmlc_compress_html_code',
'htmlc_when_logged_in',

'auto_cache_enable',
'auto_cache_max_time',
Expand Down Expand Up @@ -348,6 +349,7 @@ public function setup()
'htmlc_compress_css_code' => '1', // `0|1`.
'htmlc_compress_js_code' => '1', // `0|1`.
'htmlc_compress_html_code' => '1', // `0|1`.
'htmlc_when_logged_in' => '0', // `0|1`; enable when logged in?

/* Related to auto-cache engine. */

Expand Down
3 changes: 3 additions & 0 deletions src/includes/closures/Ac/HtmlCUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
if (!COMET_CACHE_HTMLC_ENABLE) {
return $cache; // Nothing to do here.
}
if ($self->is_user_logged_in && !COMET_CACHE_HTMLC_WHEN_LOGGED_IN) {
return $cache; // Nothing to do here.
}
// Deals with multisite base & sub-directory installs.
// e.g. `htmlc/cache/public/www-example-com` (standard WP installation).
// e.g. `htmlc/cache/public/[[/base]/child1]/www-example-com` (multisite network).
Expand Down
12 changes: 12 additions & 0 deletions src/includes/templates/advanced-cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ if (!defined('COMET_CACHE_HTMLC_ENABLE')) {
}
/*[/pro]*/
/*[pro strip-from="lite"]*/
if (!defined('COMET_CACHE_HTMLC_WHEN_LOGGED_IN')) {
/**
* Enable HTML compressor when logged in?
*
* @since 140422 First documented version.
*
* @var string|integer|boolean A boolean-ish value; e.g. `1` or `0`.
*/
define('COMET_CACHE_HTMLC_WHEN_LOGGED_IN', '%%COMET_CACHE_HTMLC_WHEN_LOGGED_IN%%');
}
/*[/pro]*/
/*[pro strip-from="lite"]*/
if (!defined('COMET_CACHE_HTMLC_CSS_EXCLUSIONS')) {
/**
* CSS exclusions for the HTML compressor.
Expand Down