LiteSpeed Cache - Version 2.3.1

Version Description

  • Jun 18 2018 =
  • [Improvement] New setting to disable Generate Critical CSS. (@cybmeta)
  • [Improvement] Added filter to can_cdn/can_optm check. (@Jacob)
  • [Update] Critical CSS Added 404 css. Limit cron interval.
  • [Update] AJAX will not bypass CDN anymore by default. (@Jacob)
  • [GUI] Show Disable All Features warning if it is on in Debug tab.
Download this release

Release Info

Developer LiteSpeedTech
Plugin Icon 128x128 LiteSpeed Cache
Version 2.3.1
Comparing to
See all releases

Code changes from version 2.2.7 to 2.3.1

Files changed (39) hide show
  1. admin/litespeed-cache-admin-display.class.php +9 -5
  2. admin/litespeed-cache-admin-report.class.php +5 -14
  3. admin/litespeed-cache-admin-settings.class.php +11 -16
  4. admin/tpl/inc/disabled_all.php +12 -0
  5. admin/tpl/manage/manage_purge.php +10 -0
  6. admin/tpl/setting/settings_cache.php +1 -1
  7. admin/tpl/setting/settings_excludes.php +2 -2
  8. admin/tpl/setting/settings_optimize.php +63 -3
  9. admin/tpl/setting/settings_tuning.php +1 -1
  10. cli/litespeed-cache-cli-admin.class.php +6 -0
  11. css/litespeed.css +8 -0
  12. inc/cdn.class.php +1 -33
  13. inc/config.class.php +38 -17
  14. inc/control.class.php +6 -6
  15. inc/css.cls.php +347 -0
  16. inc/gui.class.php +11 -0
  17. inc/litespeed-cache.class.php +6 -1
  18. inc/litespeed.autoload.php +1 -0
  19. inc/log.class.php +12 -6
  20. inc/optimize.class.php +16 -59
  21. inc/purge.class.php +22 -0
  22. inc/router.class.php +100 -6
  23. inc/task.class.php +32 -7
  24. inc/utility.class.php +7 -4
  25. includes/litespeed-cache-cdn.class.php +1 -33
  26. includes/litespeed-cache-config.class.php +38 -17
  27. includes/litespeed-cache-control.class.php +6 -6
  28. includes/litespeed-cache-gui.class.php +11 -0
  29. includes/litespeed-cache-log.class.php +12 -6
  30. includes/litespeed-cache-optimize.class.php +16 -59
  31. includes/litespeed-cache-purge.class.php +22 -0
  32. includes/litespeed-cache-router.class.php +100 -6
  33. includes/litespeed-cache-task.class.php +32 -7
  34. includes/litespeed-cache-utility.class.php +7 -4
  35. includes/litespeed-cache.class.php +6 -1
  36. includes/litespeed.autoload.php +1 -0
  37. languages/litespeed-cache.pot +231 -153
  38. litespeed-cache.php +1 -1
  39. readme.txt +13 -1
admin/litespeed-cache-admin-display.class.php CHANGED
@@ -348,12 +348,12 @@ class LiteSpeed_Cache_Admin_Display
348
* Builds the html for a single notice.
349
*
350
* @since 1.0.7
351
- * @access private
352
* @param string $color The color to use for the notice.
353
* @param string $str The notice message.
354
* @return string The built notice html.
355
*/
356
- private static function build_notice($color, $str)
357
{
358
return '<div class="' . $color . ' is-dismissible"><p>'. $str . '</p></div>' ;
359
}
@@ -671,7 +671,7 @@ class LiteSpeed_Cache_Admin_Display
671
* @param boolean $disabled If this input is disabled or not
672
* @param int $cols The width of textarea
673
*/
674
- public function build_textarea( $id, $cols = false, $val = null, $disabled = false )
675
{
676
if ( strpos( $id, '[' ) === false ) {
677
if ( $val === null ) {
@@ -688,7 +688,11 @@ class LiteSpeed_Cache_Admin_Display
688
$cols = 80 ;
689
}
690
691
- echo "<textarea name='" . LiteSpeed_Cache_Config::OPTION_NAME . "$id' rows='5' cols='$cols' $disabled>" . esc_textarea($val) . "</textarea>" ;
692
}
693
694
/**
@@ -705,7 +709,7 @@ class LiteSpeed_Cache_Admin_Display
705
// Get default val for separate item
706
$val = $this->config->get_item( $id, true ) ;
707
708
- $this->build_textarea( $id, $cols, $val ) ;
709
}
710
711
/**
348
* Builds the html for a single notice.
349
*
350
* @since 1.0.7
351
+ * @access public
352
* @param string $color The color to use for the notice.
353
* @param string $str The notice message.
354
* @return string The built notice html.
355
*/
356
+ public static function build_notice($color, $str)
357
{
358
return '<div class="' . $color . ' is-dismissible"><p>'. $str . '</p></div>' ;
359
}
671
* @param boolean $disabled If this input is disabled or not
672
* @param int $cols The width of textarea
673
*/
674
+ public function build_textarea( $id, $cols = false, $val = null, $disabled = false, $cls = '' )
675
{
676
if ( strpos( $id, '[' ) === false ) {
677
if ( $val === null ) {
688
$cols = 80 ;
689
}
690
691
+ if ( $cls ) {
692
+ $cls = " class='$cls' " ;
693
+ }
694
+
695
+ echo "<textarea name='" . LiteSpeed_Cache_Config::OPTION_NAME . "$id' rows='5' cols='$cols' $cls $disabled>" . esc_textarea($val) . "</textarea>" ;
696
}
697
698
/**
709
// Get default val for separate item
710
$val = $this->config->get_item( $id, true ) ;
711
712
+ $this->build_textarea( $id, $cols, $val, false, 'litespeed-textarea-success' ) ;
713
}
714
715
/**
admin/litespeed-cache-admin-report.class.php CHANGED
@@ -171,21 +171,12 @@ class LiteSpeed_Cache_Admin_Report
171
}
172
}
173
174
- $item_options = array(
175
- LiteSpeed_Cache_Config::EXCLUDE_OPTIMIZATION_ROLES,
176
- LiteSpeed_Cache_Config::EXCLUDE_CACHE_ROLES,
177
- LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS,
178
- LiteSpeed_Cache_Config::ITEM_CDN_MAPPING,
179
- LiteSpeed_Cache_Config::ITEM_SETTING_MODE,
180
- LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC,
181
- LiteSpeed_Cache_Config::ITEM_MEDIA_LAZY_IMG_EXC,
182
- LiteSpeed_Cache_Config::ITEM_CRWL_AS_UIDS,
183
- LiteSpeed_Cache_Config::ITEM_ADV_PURGE_ALL_HOOKS,
184
- LiteSpeed_Cache_Config::ITEM_CDN_ORI_DIR,
185
- LiteSpeed_Cache_Config::ITEM_MEDIA_WEBP_ATTRIBUTE,
186
- ) ;
187
-
188
foreach ( $item_options as $v ) {
189
$options[ $v ] = get_option( $v ) ;
190
}
191
171
}
172
}
173
174
+ $item_options = LiteSpeed_Cache_Config::get_instance()->stored_items() ;
175
foreach ( $item_options as $v ) {
176
+ // bypass main conf
177
+ if ( $v == LiteSpeed_Cache_Config::OPTION_NAME ) {
178
+ continue ;
179
+ }
180
$options[ $v ] = get_option( $v ) ;
181
}
182
admin/litespeed-cache-admin-settings.class.php CHANGED
@@ -387,10 +387,8 @@ class LiteSpeed_Cache_Admin_Settings
387
LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_LOGIN ) ;
388
}
389
390
- $id = LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ;
391
- if ( isset( $this->_input[ $id ]) ) {
392
- $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
393
- }
394
395
$ids = array(
396
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS, // Update Drop Query String @since 1.7
@@ -458,15 +456,11 @@ class LiteSpeed_Cache_Admin_Settings
458
*/
459
private function _validate_exclude()
460
{
461
- $id = LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ;
462
- if ( isset( $this->_input[ $id ] ) ) {
463
- $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
464
- }
465
466
- $id = LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ;
467
- if ( isset( $this->_input[ $id ] ) ) {
468
- $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
469
- }
470
471
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_QS ;
472
if ( isset( $this->_input[ $id ] ) ) {
@@ -721,6 +715,9 @@ class LiteSpeed_Cache_Admin_Settings
721
LiteSpeed_Cache_Config::OPID_OPTM_QS_RM,
722
LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM,
723
LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC,
724
LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER,
725
LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM,
726
LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY,
@@ -749,10 +746,8 @@ class LiteSpeed_Cache_Admin_Settings
749
update_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS, $this->_input[ LiteSpeed_Cache_Config::ITEM_OPTM_CSS ] ) ;
750
751
// prevent URI from optimization
752
- $id = LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES ;
753
- if ( isset( $this->_input[ $id ]) ) {
754
- $this->_options[ $id ] = LiteSpeed_Cache_Utility::sanitize_lines( $this->_input[ $id ], 'relative' ) ;
755
- }
756
757
// Update js deferred excludes
758
$id = LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC ;
387
LiteSpeed_Cache_Purge::add( LiteSpeed_Cache_Tag::TYPE_LOGIN ) ;
388
}
389
390
+ $id = LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV ;
391
+ $this->_save_item( $id, 'relative' ) ;
392
393
$ids = array(
394
LiteSpeed_Cache_Config::ITEM_CACHE_DROP_QS, // Update Drop Query String @since 1.7
456
*/
457
private function _validate_exclude()
458
{
459
+ $id = LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI ;
460
+ $this->_save_item( $id, 'relative' ) ;
461
462
+ $id = LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI ;
463
+ $this->_save_item( $id, 'relative' ) ;
464
465
$id = LiteSpeed_Cache_Config::OPID_EXCLUDES_QS ;
466
if ( isset( $this->_input[ $id ] ) ) {
715
LiteSpeed_Cache_Config::OPID_OPTM_QS_RM,
716
LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM,
717
LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC,
718
+ LiteSpeed_Cache_Config::OPT_OPTM_CCSS_GEN,
719
+ LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC,
720
+ LiteSpeed_Cache_Config::OPT_OPTM_CSS_ASYNC_INLINE,
721
LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER,
722
LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM,
723
LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY,
746
update_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS, $this->_input[ LiteSpeed_Cache_Config::ITEM_OPTM_CSS ] ) ;
747
748
// prevent URI from optimization
749
+ $id = LiteSpeed_Cache_Config::ITEM_OPTM_EXCLUDES ;
750
+ $this->_save_item( $id, 'relative' ) ;
751
752
// Update js deferred excludes
753
$id = LiteSpeed_Cache_Config::ITEM_OPTM_JS_DEFER_EXC ;
admin/tpl/inc/disabled_all.php ADDED
@@ -0,0 +1,12 @@
1
+ <?php
2
+ if ( ! defined( 'WPINC' ) ) die ;
3
+
4
+ if ( ! defined( 'LITESPEED_DISABLE_ALL' ) ) {
5
+ return ;
6
+ }
7
+
8
+ $err = __( 'Disable All Features', 'litespeed-cache' ) ;
9
+
10
+ // other plugin left cache expired rules in .htaccess which will cause conflicts
11
+ echo LiteSpeed_Cache_Admin_Display::build_notice( LiteSpeed_Cache_Admin_Display::NOTICE_RED, $err ) ;
12
+
admin/tpl/manage/manage_purge.php CHANGED
@@ -67,6 +67,16 @@ if ( LiteSpeed_Cache_Router::opcache_enabled() ) {
67
) ;
68
}
69
70
$_panels[] = array(
71
'title' => __( 'Purge All', 'litespeed-cache' ),
72
'desc' => __( 'Purge the cache entries created by this plugin', 'litespeed-cache' ),
67
) ;
68
}
69
70
+ if ( LiteSpeed_Cache_CSS::has_ccss_cache() ) {
71
+ $_panels[] = array(
72
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Critical CSS', 'litespeed-cache' ),
73
+ 'desc' => __( 'This will delete all generated critical CSS files', 'litespeed-cache' ),
74
+ 'icon' => 'purge-cssjs',
75
+ 'append_url' => LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_CCSS,
76
+ ) ;
77
+ }
78
+
79
+
80
$_panels[] = array(
81
'title' => __( 'Purge All', 'litespeed-cache' ),
82
'desc' => __( 'Purge the cache entries created by this plugin', 'litespeed-cache' ),
admin/tpl/setting/settings_cache.php CHANGED
@@ -61,7 +61,7 @@ if ( ! defined( 'WPINC' ) ) die ;
61
<tr <?php echo $_hide_in_basic_mode ; ?>>
62
<th><?php echo __( 'Private Cached URIs', 'litespeed-cache' ) ; ?></th>
63
<td>
64
- <?php $this->build_textarea(LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV); ?>
65
<div class="litespeed-desc">
66
<?php echo __('URI Paths containing these strings will NOT be cached as public.', 'litespeed-cache'); ?>
67
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
61
<tr <?php echo $_hide_in_basic_mode ; ?>>
62
<th><?php echo __( 'Private Cached URIs', 'litespeed-cache' ) ; ?></th>
63
<td>
64
+ <?php $this->build_textarea2( LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV ) ; ?>
65
<div class="litespeed-desc">
66
<?php echo __('URI Paths containing these strings will NOT be cached as public.', 'litespeed-cache'); ?>
67
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
admin/tpl/setting/settings_excludes.php CHANGED
@@ -13,7 +13,7 @@ if ( ! defined( 'WPINC' ) ) die ;
13
<tr>
14
<th><?php echo __( 'Force Cache URIs', 'litespeed-cache' ) ; ?></th>
15
<td>
16
- <?php $this->build_textarea( LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ) ; ?>
17
<div class="litespeed-desc">
18
<?php echo __('Paths containing these strings will be cached regardless of no-cacheable settings.', 'litespeed-cache'); ?>
19
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
@@ -31,7 +31,7 @@ if ( ! defined( 'WPINC' ) ) die ;
31
<tr>
32
<th><?php echo __( 'Do Not Cache URIs', 'litespeed-cache' ) ; ?></th>
33
<td>
34
- <?php $this->build_textarea(LiteSpeed_Cache_Config::OPID_EXCLUDES_URI); ?>
35
<div class="litespeed-desc">
36
<?php echo __('Paths containing these strings will not be cached.', 'litespeed-cache'); ?>
37
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
13
<tr>
14
<th><?php echo __( 'Force Cache URIs', 'litespeed-cache' ) ; ?></th>
15
<td>
16
+ <?php $this->build_textarea2( LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI ) ; ?>
17
<div class="litespeed-desc">
18
<?php echo __('Paths containing these strings will be cached regardless of no-cacheable settings.', 'litespeed-cache'); ?>
19
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
31
<tr>
32
<th><?php echo __( 'Do Not Cache URIs', 'litespeed-cache' ) ; ?></th>
33
<td>
34
+ <?php $this->build_textarea2( LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI ) ; ?>
35
<div class="litespeed-desc">
36
<?php echo __('Paths containing these strings will not be cached.', 'litespeed-cache'); ?>
37
<?php echo __('The URLs will be compared to the REQUEST_URI server variable.', 'litespeed-cache'); ?>
admin/tpl/setting/settings_optimize.php CHANGED
@@ -1,6 +1,8 @@
1
<?php
2
if ( ! defined( 'WPINC' ) ) die ;
3
4
?>
5
6
<h3 class="litespeed-title-short">
@@ -131,8 +133,9 @@ if ( ! defined( 'WPINC' ) ) die ;
131
<td>
132
<?php $this->build_switch( LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC ) ; ?>
133
<div class="litespeed-desc">
134
- <?php echo __( 'Optimize CSS delivery. This will load Google Fonts asynchronously too.', 'litespeed-cache' ) ; ?>
135
- <?php echo __( 'This can improve your speed score in services like Pingdom, GTmetrix and PageSpeed.', 'litespeed-cache' ) ; ?>
136
<br /><font class="litespeed-success">
137
<?php echo __('API', 'litespeed-cache'); ?>:
138
<?php echo sprintf( __( 'Elements with attribute %s in html code will be excluded.', 'litespeed-cache' ), '<code>data-no-async="1"</code>' ) ; ?>
@@ -141,6 +144,63 @@ if ( ! defined( 'WPINC' ) ) die ;
141
</td>
142
</tr>
143
144
<tr>
145
<th><?php echo __( 'Load JS Deferred', 'litespeed-cache' ) ; ?></th>
146
<td>
@@ -173,8 +233,8 @@ if ( ! defined( 'WPINC' ) ) die ;
173
<div class="litespeed-desc">
174
<?php echo __( 'Prefetching DNS can reduce latency for visiters.', 'litespeed-cache' ) ; ?>
175
<?php echo __( 'For example', 'litespeed-cache' ) ; ?>: <code>//www.example.com</code>
176
- <a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:optimize#dns_prefetch" target="_blank"><?php echo __( 'Learn More', 'litespeed-cache' ) ; ?></a>
177
<?php echo __( 'One per line.', 'litespeed-cache' ) ; ?>
178
</div>
179
</td>
180
</tr>
1
<?php
2
if ( ! defined( 'WPINC' ) ) die ;
3
4
+ $last_critical_css_generated = LiteSpeed_Cache_CSS::get_summary() ;
5
+
6
?>
7
8
<h3 class="litespeed-title-short">
133
<td>
134
<?php $this->build_switch( LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC ) ; ?>
135
<div class="litespeed-desc">
136
+ <?php echo __( 'Optimize CSS delivery.', 'litespeed-cache' ) ; ?>
137
+ <?php echo __( 'This can improve your speed score in services like Pingdom, GTmetrix and PageSpeed.', 'litespeed-cache' ) ; ?><br />
138
+ <?php echo sprintf( __( 'When this option is turned %s, it will also load Google Fonts asynchronously.', 'litespeed-cache' ), '<code>' . __( 'ON', 'litespeed-cache' ) . '</code>' ) ; ?>
139
<br /><font class="litespeed-success">
140
<?php echo __('API', 'litespeed-cache'); ?>:
141
<?php echo sprintf( __( 'Elements with attribute %s in html code will be excluded.', 'litespeed-cache' ), '<code>data-no-async="1"</code>' ) ; ?>
144
</td>
145
</tr>
146
147
+ <tr>
148
+ <th><?php echo __( 'Generate Critical CSS', 'litespeed-cache' ) ; ?></th>
149
+ <td>
150
+ <?php $this->build_switch( LiteSpeed_Cache_Config::OPT_OPTM_CCSS_GEN ) ; ?>
151
+ <div class="litespeed-desc">
152
+ <?php echo sprintf( __( 'Leave this option %1$s to allow communication with LiteSpeed CCSS server. If set to %2$s, Critical CSS will not be generated.', 'litespeed-cache' ), '<code>' . __( 'ON', 'litespeed-cache' ) . '</code>', '<code>' . __( 'OFF', 'litespeed-cache' ) . '</code>' ) ; ?><br />
153
+ <?php echo sprintf( __( 'This option only works if %1$s is %2$s.', 'litespeed-cache' ), '<code>' . __( 'Load CSS Asynchronously', 'litespeed-cache' ) . '</code>', '<code>' . __( 'ON', 'litespeed-cache' ) . '</code>' ) ; ?>
154
+ </div>
155
+ </td>
156
+ </tr>
157
+
158
+ <tr>
159
+ <th><?php echo __( 'Generate Critical CSS In Background', 'litespeed-cache' ) ; ?></th>
160
+ <td>
161
+ <?php $this->build_switch( LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC ) ; ?>
162
+ <div class="litespeed-desc">
163
+ <?php echo __( 'Automatically generate critical CSS in the background via a cron-based queue.', 'litespeed-cache' ) ; ?>
164
+ <?php echo sprintf( __( 'If set to %s this is done in the foreground, which may slow down page load.', 'litespeed-cache' ), '<code>' . __('OFF', 'litespeed-cache') . '</code>' ) ; ?>
165
+ <a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:optimize#generate_critical_css" target="_blank"><?php echo __( 'Learn More', 'litespeed-cache' ) ; ?></a>
166
+ </div>
167
+
168
+ <?php if ( $last_critical_css_generated ) : ?>
169
+ <div class="litespeed-desc litespeed-left20">
170
+ <?php if ( ! empty( $last_critical_css_generated[ 'last_request' ] ) ) : ?>
171
+ <p>
172
+ <?php echo __( 'Last generated', 'litespeed-cache' ) . ': <code>' . LiteSpeed_Cache_Utility::readable_time( $last_critical_css_generated[ 'last_request' ] ) . '</code>' ; ?>
173
+ </p>
174
+ <p>
175
+ <?php echo __( 'Last requested cost', 'litespeed-cache' ) . ': <code>' . $last_critical_css_generated[ 'last_spent' ] . 's</code>' ; ?>
176
+ </p>
177
+ <?php endif ; ?>
178
+ <?php if ( ! empty( $last_critical_css_generated[ 'queue' ] ) ) : ?>
179
+ <div class="litespeed-callout-warning">
180
+ <h4><?php echo __( 'URL list in queue waiting for cron','litespeed-cache' ) ; ?></h4>
181
+ <p>
182
+ <?php echo implode( '<br />', $last_critical_css_generated[ 'queue' ] ) ; ?>
183
+ </p>
184
+ </p>
185
+ <a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_CSS, LiteSpeed_Cache_CSS::TYPE_GENERATE_CRITICAL ) ; ?>" class="litespeed-btn-success">
186
+ <?php echo __( 'Run Queue Manually', 'litespeed-cache' ) ; ?>
187
+ </a>
188
+ <?php endif ; ?>
189
+ </div>
190
+ <?php endif ; ?>
191
+ </td>
192
+ </tr>
193
+
194
+ <tr>
195
+ <th><?php echo __( 'Inline CSS Async Lib', 'litespeed-cache' ) ; ?></th>
196
+ <td>
197
+ <?php $this->build_switch( LiteSpeed_Cache_Config::OPT_OPTM_CSS_ASYNC_INLINE ) ; ?>
198
+ <div class="litespeed-desc">
199
+ <?php echo __( 'This will inline the asynchronous CSS library to avoid render blocking.', 'litespeed-cache' ) ; ?>
200
+ </div>
201
+ </td>
202
+ </tr>
203
+
204
<tr>
205
<th><?php echo __( 'Load JS Deferred', 'litespeed-cache' ) ; ?></th>
206
<td>
233
<div class="litespeed-desc">
234
<?php echo __( 'Prefetching DNS can reduce latency for visiters.', 'litespeed-cache' ) ; ?>
235
<?php echo __( 'For example', 'litespeed-cache' ) ; ?>: <code>//www.example.com</code>
236
<?php echo __( 'One per line.', 'litespeed-cache' ) ; ?>
237
+ <a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:configuration:optimize#dns_prefetch" target="_blank"><?php echo __( 'Learn More', 'litespeed-cache' ) ; ?></a>
238
</div>
239
</td>
240
</tr>
admin/tpl/setting/settings_tuning.php CHANGED
@@ -167,7 +167,7 @@ if ( ! defined( 'WPINC' ) ) die ;
167
<tr>
168
<th><?php echo __( 'URI Excludes', 'litespeed-cache' ) ; ?></th>
169
<td>
170
- <?php $this->build_textarea(LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES); ?>
171
<div class="litespeed-desc">
172
<?php echo __( 'Prevent any optimization of listed pages.', 'litespeed-cache' ) ; ?>
173
<?php echo __( 'Both full URLs and partial strings can be used.', 'litespeed-cache' ) ; ?>
167
<tr>
168
<th><?php echo __( 'URI Excludes', 'litespeed-cache' ) ; ?></th>
169
<td>
170
+ <?php $this->build_textarea2( LiteSpeed_Cache_Config::ITEM_OPTM_EXCLUDES ) ; ?>
171
<div class="litespeed-desc">
172
<?php echo __( 'Prevent any optimization of listed pages.', 'litespeed-cache' ) ; ?>
173
<?php echo __( 'Both full URLs and partial strings can be used.', 'litespeed-cache' ) ; ?>
cli/litespeed-cache-cli-admin.class.php CHANGED
@@ -53,6 +53,9 @@ class LiteSpeed_Cache_Cli_Admin
53
LiteSpeed_Cache_Config::OPID_OPTM_QS_RM,
54
LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM,
55
LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC,
56
LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER,
57
LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM,
58
LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY,
@@ -162,6 +165,9 @@ class LiteSpeed_Cache_Cli_Admin
162
case LiteSpeed_Cache_Config::OPID_OPTM_QS_RM:
163
case LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM:
164
case LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC:
165
case LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER:
166
case LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM:
167
case LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY:
53
LiteSpeed_Cache_Config::OPID_OPTM_QS_RM,
54
LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM,
55
LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC,
56
+ LiteSpeed_Cache_Config::OPT_OPTM_CCSS_GEN,
57
+ LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC,
58
+ LiteSpeed_Cache_Config::OPT_OPTM_CSS_ASYNC_INLINE,
59
LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER,
60
LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM,
61
LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY,
165
case LiteSpeed_Cache_Config::OPID_OPTM_QS_RM:
166
case LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_RM:
167
case LiteSpeed_Cache_Config::OPID_OPTM_CSS_ASYNC:
168
+ case LiteSpeed_Cache_Config::OPT_OPTM_CCSS_GEN:
169
+ case LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC:
170
+ case LiteSpeed_Cache_Config::OPT_OPTM_CSS_ASYNC_INLINE:
171
case LiteSpeed_Cache_Config::OPID_OPTM_JS_DEFER:
172
case LiteSpeed_Cache_Config::OPID_OPTM_EMOJI_RM:
173
case LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY:
css/litespeed.css CHANGED
@@ -1648,6 +1648,10 @@ input.litespeed-input[type="file"]{
1648
1649
/********************************* todo *******************************/
1650
1651
/* input field */
1652
.litespeed-textarea {
1653
width: 60% ;
@@ -1711,6 +1715,10 @@ input.litespeed-input[type="file"]{
1711
font-family: "Open Sans", Arial, sans-serif;
1712
}
1713
1714
.litespeed .litespeed-regular-text,
1715
.litespeed-regular-text {
1716
padding-left: 5px;
1648
1649
/********************************* todo *******************************/
1650
1651
+ .litespeed-body .litespeed-textarea-success {
1652
+ border-color: #6699cc ;
1653
+ }
1654
+
1655
/* input field */
1656
.litespeed-textarea {
1657
width: 60% ;
1715
font-family: "Open Sans", Arial, sans-serif;
1716
}
1717
1718
+ .litespeed-body textarea {
1719
+ border-color: #69B1FF ;
1720
+ }
1721
+
1722
.litespeed .litespeed-regular-text,
1723
.litespeed-regular-text {
1724
padding-left: 5px;
inc/cdn.class.php CHANGED
@@ -37,7 +37,7 @@ class LiteSpeed_Cache_CDN
37
{
38
LiteSpeed_Cache_Log::debug2( 'CDN init' ) ;
39
40
- if ( ! $this->can_cdn() ) {
41
if ( ! defined( self::BYPASS ) ) {
42
define( self::BYPASS, true ) ;
43
}
@@ -235,38 +235,6 @@ class LiteSpeed_Cache_CDN
235
return $instance->content ;
236
}
237
238
- /**
239
- * Check if it can use CDN replacement
240
- *
241
- * @since 1.2.3
242
- * @access public
243
- */
244
- public function can_cdn()
245
- {
246
- if ( is_admin() ) {
247
- return false ;
248
- }
249
-
250
- if ( is_feed() ) {
251
- return false ;
252
- }
253
-
254
- if ( is_preview() ) {
255
- return false ;
256
- }
257
-
258
- /**
259
- * Bypass login/reg page
260
- * @since 1.6
261
- */
262
- if ( in_array( $GLOBALS[ 'pagenow' ], array( 'wp-login.php', 'wp-register.php' ), true ) ) {
263
- LiteSpeed_Cache_Log::debug( 'CDN bypassed as is login/reg page' ) ;
264
- return false ;
265
- }
266
-
267
- return true ;
268
- }
269
-
270
/**
271
* Replace CDN url
272
*
37
{
38
LiteSpeed_Cache_Log::debug2( 'CDN init' ) ;
39
40
+ if ( ! LiteSpeed_Cache_Router::can_cdn() ) {
41
if ( ! defined( self::BYPASS ) ) {
42
define( self::BYPASS, true ) ;
43
}
235
return $instance->content ;
236
}
237
238
/**
239
* Replace CDN url
240
*
inc/config.class.php CHANGED
@@ -35,6 +35,10 @@ class LiteSpeed_Cache_Config
35
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
36
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
37
const ITEM_MEDIA_WEBP_ATTRIBUTE = 'litespeed-media-webp_attribute' ;
38
39
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
40
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
@@ -73,7 +77,6 @@ class LiteSpeed_Cache_Config
73
const OPID_CACHE_RES = 'cache_resources' ;
74
const OPID_CACHE_MOBILE = 'mobileview_enabled' ;
75
const ID_MOBILEVIEW_LIST = 'mobileview_rules' ;
76
- const OPID_CACHE_URI_PRIV = 'cache_uri_priv' ;
77
const OPID_CACHE_OBJECT = 'cache_object' ;
78
const OPID_CACHE_OBJECT_KIND = 'cache_object_kind' ;
79
const OPID_CACHE_OBJECT_HOST = 'cache_object_host' ;
@@ -130,8 +133,7 @@ class LiteSpeed_Cache_Config
130
const PURGE_DATE = 'D' ;
131
const PURGE_TERM = 'T' ; // include category|tag|tax
132
const PURGE_POST_TYPE = 'PT' ;
133
- const OPID_FORCE_CACHE_URI = 'forced_cache_uri' ;
134
- const OPID_EXCLUDES_URI = 'excludes_uri' ;
135
const OPID_EXCLUDES_QS = 'excludes_qs' ;
136
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
137
const OPID_EXCLUDES_TAG = 'excludes_tag' ;
@@ -156,9 +158,11 @@ class LiteSpeed_Cache_Config
156
const OPID_OPTM_QS_RM = 'optm_qs_rm' ;
157
const OPID_OPTM_GGFONTS_RM = 'optm_ggfonts_rm' ;
158
const OPID_OPTM_CSS_ASYNC = 'optm_css_async' ;
159
const OPID_OPTM_JS_DEFER = 'optm_js_defer' ;
160
const OPID_OPTM_EMOJI_RM = 'optm_emoji_rm' ;
161
- const OPID_OPTM_EXCLUDES = 'optm_excludes' ;
162
const OPID_OPTM_EXC_JQUERY = 'optm_exclude_jquery' ;
163
const OPID_OPTM_GGFONTS_ASYNC = 'optm_ggfonts_async' ;
164
const OPID_OPTM_MAX_SIZE = 'optm_max_size' ;
@@ -293,6 +297,10 @@ class LiteSpeed_Cache_Config
293
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
294
self::ITEM_CRWL_AS_UIDS,
295
self::ITEM_ADV_PURGE_ALL_HOOKS,
296
) ;
297
}
298
@@ -456,20 +464,20 @@ class LiteSpeed_Cache_Config
456
457
switch ( $type ) {
458
case 'forced_cache' :
459
- $id = self::OPID_FORCE_CACHE_URI ;
460
break ;
461
462
case 'private' :
463
- $id = self::OPID_CACHE_URI_PRIV ;
464
break ;
465
466
case 'nonoptimize' :
467
- $id = self::OPID_OPTM_EXCLUDES ;
468
break ;
469
470
case 'nocache' :
471
default:
472
- $id = self::OPID_EXCLUDES_URI ;
473
break ;
474
}
475
@@ -477,12 +485,9 @@ class LiteSpeed_Cache_Config
477
$list = $instance->get_item( $id ) ;
478
479
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
480
- $list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
481
- $list = array_unique( $list ) ;
482
- $list = array_filter( $list ) ;
483
- $list = implode( "\n", $list ) ;
484
485
- $instance->update_options( array( $id => $list ) ) ;
486
487
// Purge this page & redirect
488
LiteSpeed_Cache_Purge::purge_front() ;
@@ -627,7 +632,6 @@ class LiteSpeed_Cache_Config
627
self::OPID_CACHE_RES => true,
628
self::OPID_CACHE_MOBILE => false,
629
self::ID_MOBILEVIEW_LIST => false,
630
- self::OPID_CACHE_URI_PRIV => '',
631
self::OPID_CACHE_OBJECT => false,
632
self::OPID_CACHE_OBJECT_KIND => false,
633
self::OPID_CACHE_OBJECT_HOST => 'localhost',
@@ -662,8 +666,6 @@ class LiteSpeed_Cache_Config
662
self::OPID_404_TTL => 3600,
663
self::OPID_500_TTL => 3600,
664
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
665
- self::OPID_FORCE_CACHE_URI => '',
666
- self::OPID_EXCLUDES_URI => '',
667
self::OPID_EXCLUDES_QS => '',
668
self::OPID_EXCLUDES_CAT => '',
669
self::OPID_EXCLUDES_TAG => '',
@@ -688,9 +690,11 @@ class LiteSpeed_Cache_Config
688
self::OPID_OPTM_QS_RM => false,
689
self::OPID_OPTM_GGFONTS_RM => false,
690
self::OPID_OPTM_CSS_ASYNC => false,
691
self::OPID_OPTM_JS_DEFER => false,
692
self::OPID_OPTM_EMOJI_RM => false,
693
- self::OPID_OPTM_EXCLUDES => '',
694
self::OPID_OPTM_EXC_JQUERY => true,
695
self::OPID_OPTM_GGFONTS_ASYNC => false,
696
self::OPID_OPTM_MAX_SIZE => 1.2,
@@ -996,6 +1000,23 @@ class LiteSpeed_Cache_Config
996
LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
997
}
998
999
$this->options = self::option_diff( $default_options, $this->options ) ;
1000
1001
$res = $this->update_options() ;
35
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
36
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
37
const ITEM_MEDIA_WEBP_ATTRIBUTE = 'litespeed-media-webp_attribute' ;
38
+ const ITEM_FORCE_CACHE_URI = 'litespeed-forced_cache_uri' ;
39
+ const ITEM_CACHE_URI_PRIV = 'litespeed-cache_uri_priv' ;
40
+ const ITEM_OPTM_EXCLUDES = 'litespeed-optm_excludes' ;
41
+ const ITEM_EXCLUDES_URI = 'litespeed-excludes_uri' ;
42
43
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
44
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
77
const OPID_CACHE_RES = 'cache_resources' ;
78
const OPID_CACHE_MOBILE = 'mobileview_enabled' ;
79
const ID_MOBILEVIEW_LIST = 'mobileview_rules' ;
80
const OPID_CACHE_OBJECT = 'cache_object' ;
81
const OPID_CACHE_OBJECT_KIND = 'cache_object_kind' ;
82
const OPID_CACHE_OBJECT_HOST = 'cache_object_host' ;
133
const PURGE_DATE = 'D' ;
134
const PURGE_TERM = 'T' ; // include category|tag|tax
135
const PURGE_POST_TYPE = 'PT' ;
136
+
137
const OPID_EXCLUDES_QS = 'excludes_qs' ;
138
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
139
const OPID_EXCLUDES_TAG = 'excludes_tag' ;
158
const OPID_OPTM_QS_RM = 'optm_qs_rm' ;
159
const OPID_OPTM_GGFONTS_RM = 'optm_ggfonts_rm' ;
160
const OPID_OPTM_CSS_ASYNC = 'optm_css_async' ;
161
+ const OPT_OPTM_CCSS_GEN = 'optm_ccss_gen' ;
162
+ const OPT_OPTM_CCSS_ASYNC = 'optm_ccss_async' ;
163
+ const OPT_OPTM_CSS_ASYNC_INLINE = 'optm_css_async_inline' ;
164
const OPID_OPTM_JS_DEFER = 'optm_js_defer' ;
165
const OPID_OPTM_EMOJI_RM = 'optm_emoji_rm' ;
166
const OPID_OPTM_EXC_JQUERY = 'optm_exclude_jquery' ;
167
const OPID_OPTM_GGFONTS_ASYNC = 'optm_ggfonts_async' ;
168
const OPID_OPTM_MAX_SIZE = 'optm_max_size' ;
297
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
298
self::ITEM_CRWL_AS_UIDS,
299
self::ITEM_ADV_PURGE_ALL_HOOKS,
300
+ self::ITEM_FORCE_CACHE_URI,
301
+ self::ITEM_CACHE_URI_PRIV,
302
+ self::ITEM_OPTM_EXCLUDES,
303
+ self::ITEM_EXCLUDES_URI,
304
) ;
305
}
306
464
465
switch ( $type ) {
466
case 'forced_cache' :
467
+ $id = self::ITEM_FORCE_CACHE_URI ;
468
break ;
469
470
case 'private' :
471
+ $id = self::ITEM_CACHE_URI_PRIV ;
472
break ;
473
474
case 'nonoptimize' :
475
+ $id = self::ITEM_OPTM_EXCLUDES ;
476
break ;
477
478
case 'nocache' :
479
default:
480
+ $id = self::ITEM_EXCLUDES_URI ;
481
break ;
482
}
483
485
$list = $instance->get_item( $id ) ;
486
487
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
488
+ $list = LiteSpeed_Cache_Utility::sanitize_lines( $list, 'relative' ) ;
489
490
+ update_option( $id, $list ) ;
491
492
// Purge this page & redirect
493
LiteSpeed_Cache_Purge::purge_front() ;
632
self::OPID_CACHE_RES => true,
633
self::OPID_CACHE_MOBILE => false,
634
self::ID_MOBILEVIEW_LIST => false,
635
self::OPID_CACHE_OBJECT => false,
636
self::OPID_CACHE_OBJECT_KIND => false,
637
self::OPID_CACHE_OBJECT_HOST => 'localhost',
666
self::OPID_404_TTL => 3600,
667
self::OPID_500_TTL => 3600,
668
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
669
self::OPID_EXCLUDES_QS => '',
670
self::OPID_EXCLUDES_CAT => '',
671
self::OPID_EXCLUDES_TAG => '',
690
self::OPID_OPTM_QS_RM => false,
691
self::OPID_OPTM_GGFONTS_RM => false,
692
self::OPID_OPTM_CSS_ASYNC => false,
693
+ self::OPT_OPTM_CCSS_GEN => true,
694
+ self::OPT_OPTM_CCSS_ASYNC => true,
695
+ self::OPT_OPTM_CSS_ASYNC_INLINE => true,
696
self::OPID_OPTM_JS_DEFER => false,
697
self::OPID_OPTM_EMOJI_RM => false,
698
self::OPID_OPTM_EXC_JQUERY => true,
699
self::OPID_OPTM_GGFONTS_ASYNC => false,
700
self::OPID_OPTM_MAX_SIZE => 1.2,
1000
LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
1001
}
1002
1003
+ /**
1004
+ * Move Exclude settings to separate item
1005
+ * @since 2.3
1006
+ */
1007
+ if ( isset( $this->options[ 'forced_cache_uri' ] ) ) {
1008
+ update_option( LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI, $this->options[ 'forced_cache_uri' ] ) ;
1009
+ }
1010
+ if ( isset( $this->options[ 'cache_uri_priv' ] ) ) {
1011
+ update_option( LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV, $this->options[ 'cache_uri_priv' ] ) ;
1012
+ }
1013
+ if ( isset( $this->options[ 'optm_excludes' ] ) ) {
1014
+ update_option( LiteSpeed_Cache_Config::ITEM_OPTM_EXCLUDES, $this->options[ 'optm_excludes' ] ) ;
1015
+ }
1016
+ if ( isset( $this->options[ 'excludes_uri' ] ) ) {
1017
+ update_option( LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI, $this->options[ 'excludes_uri' ] ) ;
1018
+ }
1019
+
1020
$this->options = self::option_diff( $default_options, $this->options ) ;
1021
1022
$res = $this->update_options() ;
inc/control.class.php CHANGED
@@ -514,9 +514,9 @@ class LiteSpeed_Cache_Control
514
public static function finalize()
515
{
516
// Check if URI is forced cache
517
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ) ;
518
if ( ! empty( $excludes ) ) {
519
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
520
if ( $result ) {
521
self::force_cacheable() ;
522
LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ) ;
@@ -635,9 +635,9 @@ class LiteSpeed_Cache_Control
635
// }
636
637
// Check private cache URI setting
638
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ) ;
639
if ( ! empty( $excludes ) ) {
640
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
641
if ( $result ) {
642
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
643
}
@@ -646,9 +646,9 @@ class LiteSpeed_Cache_Control
646
if ( ! self::is_forced_cacheable() ) {
647
648
// Check if URI is excluded from cache
649
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ) ;
650
if ( ! empty( $excludes ) ) {
651
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
652
if ( $result ) {
653
return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
654
}
514
public static function finalize()
515
{
516
// Check if URI is forced cache
517
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI ) ;
518
if ( ! empty( $excludes ) ) {
519
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
520
if ( $result ) {
521
self::force_cacheable() ;
522
LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ) ;
635
// }
636
637
// Check private cache URI setting
638
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV ) ;
639
if ( ! empty( $excludes ) ) {
640
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
641
if ( $result ) {
642
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
643
}
646
if ( ! self::is_forced_cacheable() ) {
647
648
// Check if URI is excluded from cache
649
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI ) ;
650
if ( ! empty( $excludes ) ) {
651
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
652
if ( $result ) {
653
return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
654
}
inc/css.cls.php ADDED
@@ -0,0 +1,347 @@
1
+ <?php
2
+
3
+ /**
4
+ * The optimize css class.
5
+ *
6
+ * @since 2.3
7
+ * @package LiteSpeed_Cache
8
+ * @subpackage LiteSpeed_Cache/inc
9
+ * @author LiteSpeed Technologies <info@litespeedtech.com>
10
+ */
11
+
12
+ class LiteSpeed_Cache_CSS
13
+ {
14
+ private static $_instance ;
15
+
16
+ const TYPE_GENERATE_CRITICAL = 'generate_critical' ;
17
+
18
+ const DB_CCSS_SUMMARY = 'litespeed-ccss-summary' ;
19
+
20
+ /**
21
+ * Output critical css
22
+ *
23
+ * @since 1.3
24
+ * @since 2.3 Migrated from optimize.cls
25
+ * @access public
26
+ */
27
+ public static function prepend_ccss( $html_head )
28
+ {
29
+ // Get critical css for current page
30
+ // Note: need to consider mobile
31
+ $rules = self::get_instance()->_ccss() ;
32
+
33
+ // Append default critical css
34
+ $rules .= get_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS ) ;
35
+
36
+ $html_head = '<style id="litespeed-optm-css-rules">' . $rules . '</style>' . $html_head ;
37
+
38
+ return $html_head ;
39
+ }
40
+
41
+ /**
42
+ * Check if there is a queue for cron or not
43
+ *
44
+ * @since 2.3
45
+ * @access public
46
+ */
47
+ public static function has_queue()
48
+ {
49
+ $req_summary = self::get_summary() ;
50
+ if ( ! empty( $req_summary[ 'queue' ] ) ) {
51
+ return true ;
52
+ }
53
+
54
+ return false ;
55
+ }
56
+
57
+ /**
58
+ * Check if there is a ccss cache folder
59
+ *
60
+ * @since 2.3
61
+ * @access public
62
+ */
63
+ public static function has_ccss_cache()
64
+ {
65
+ return is_dir( LSCWP_CONTENT_DIR . '/cache/ccss' ) ;
66
+ }
67
+
68
+ /**
69
+ * Save ccss summary
70
+ *
71
+ * @since 2.3
72
+ * @access private
73
+ */
74
+ private function _save_summary( $data )
75
+ {
76
+ update_option( self::DB_CCSS_SUMMARY, $data ) ;
77
+ }
78
+
79
+ /**
80
+ * Read last time generated info
81
+ *
82
+ * @since 2.3
83
+ * @access public
84
+ */
85
+ public static function get_summary()
86
+ {
87
+ return get_option( self::DB_CCSS_SUMMARY, array() ) ;
88
+ }
89
+
90
+ /**
91
+ * Generate realpath of ccss
92
+ *
93
+ * @since 2.3
94
+ * @access public
95
+ */
96
+ public static function ccss_realpath( $ccss_type )
97
+ {
98
+ return LSCWP_CONTENT_DIR . "/cache/ccss/$ccss_type.css" ;
99
+ }
100
+
101
+ /**
102
+ * Delete file-based cache folder
103
+ *
104
+ * @since 2.3
105
+ * @access public
106
+ */
107
+ public function rm_cache_folder()
108
+ {
109
+ if ( file_exists( LSCWP_CONTENT_DIR . '/cache/ccss' ) ) {
110
+ Litespeed_File::rrmdir( LSCWP_CONTENT_DIR . '/cache/ccss' ) ;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * The critical css content of the current page
116
+ *
117
+ * @since 2.3
118
+ * @access private
119
+ */
120
+ private function _ccss()
121
+ {
122
+ // If don't need to generate CCSS, bypass
123
+ if ( ! LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPT_OPTM_CCSS_GEN ) ) {
124
+ LiteSpeed_Cache_Log::debug( '[CSS] bypassed ccss due to setting' ) ;
125
+ return '' ;
126
+ }
127
+
128
+ $ccss_type = $this->_which_css() ;
129
+ $ccss_file = self::ccss_realpath( $ccss_type ) ;
130
+
131
+ if ( file_exists( $ccss_file ) ) {
132
+ LiteSpeed_Cache_Log::debug2( '[CSS] existing ccss ' . $ccss_file ) ;
133
+ return Litespeed_File::read( $ccss_file ) ;
134
+ }
135
+
136
+ // Check if is already in a request, bypass current one
137
+ $req_summary = self::get_summary() ;
138
+ if ( $req_summary && ! empty( $req_summary[ 'curr_request' ] ) && time() - $req_summary[ 'curr_request' ] < 300 ) {
139
+ return '' ;
140
+ }
141
+
142
+ global $wp ;
143
+ $request_url = home_url( $wp->request ) ;
144
+
145
+ // If generate in backend, log it and bypass
146
+ if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC ) ) {
147
+ // Store it to prepare for cron
148
+ if ( empty( $req_summary[ 'queue' ] ) ) {
149
+ $req_summary[ 'queue' ] = array() ;
150
+ }
151
+ $req_summary[ 'queue' ][ $ccss_type ] = $request_url ;
152
+ LiteSpeed_Cache_Log::debug( '[CSS] Added queue [type] ' . $ccss_type . ' [url] ' . $request_url ) ;
153
+
154
+ $this->_save_summary( $req_summary ) ;
155
+ return '' ;
156
+ }
157
+
158
+ // generate on the fly
159
+ return $this->_generate_ccss( $request_url, $ccss_type ) ;
160
+ }
161
+
162
+ /**
163
+ * Cron ccss generation
164
+ *
165
+ * @since 2.3
166
+ * @access private
167
+ */
168
+ public static function cron_ccss( $continue = false )
169
+ {
170
+ $req_summary = self::get_summary() ;
171
+ if ( empty( $req_summary[ 'queue' ] ) ) {
172
+ return ;
173
+ }
174
+
175
+ // For cron, need to check request interval too
176
+ if ( ! $continue ) {
177
+ if ( $req_summary && ! empty( $req_summary[ 'curr_request' ] ) && time() - $req_summary[ 'curr_request' ] < 300 ) {
178
+ return ;
179
+ }
180
+ }
181
+
182
+ foreach ( $req_summary[ 'queue' ] as $k => $v ) {
183
+ LiteSpeed_Cache_Log::debug( '[CSS] cron job [type] ' . $k . ' [url] ' . $v ) ;
184
+
185
+ self::get_instance()->_generate_ccss( $v, $k ) ;
186
+
187
+ // only request first one
188
+ if ( ! $continue ) {
189
+ return ;
190
+ }
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Send to LiteSpeed CSS API to generate CSS
196
+ *
197
+ * @since 2.3
198
+ * @access private
199
+ */
200
+ private function _generate_ccss( $request_url, $ccss_type )
201
+ {
202
+ $req_summary = self::get_summary() ;
203
+
204
+ $ccss_file = self::ccss_realpath( $ccss_type ) ;
205
+
206
+ // Update css request status
207
+ $req_summary[ 'curr_request' ] = time() ;
208
+ $this->_save_summary( $req_summary ) ;
209
+
210
+ // Generate critical css
211
+ $url = 'http://ccss.api.litespeedtech.com' ;
212
+
213
+ $data = array(
214
+ 'home_url' => home_url(),
215
+ 'url' => $request_url,
216
+ 'ccss_type' => $ccss_type,
217
+ ) ;
218
+
219
+ LiteSpeed_Cache_Log::debug( '[CSS] posting to : ' . $url, $data ) ;
220
+
221
+ $param = array(
222
+ 'v' => LiteSpeed_Cache::PLUGIN_VERSION,
223
+ 'data' => $data,
224
+ ) ;
225
+
226
+ $response = wp_remote_post( $url, array( 'body' => $param, 'timeout' => 15 ) ) ;
227
+
228
+ // Parse response data
229
+ if ( is_wp_error( $response ) ) {
230
+ $error_message = $response->get_error_message() ;
231
+ LiteSpeed_Cache_Log::debug( '[CSS] failed to post: ' . $error_message ) ;
232
+ return false ;
233
+ }
234
+
235
+ $json = json_decode( $response[ 'body' ], true ) ;
236
+ if ( ! is_array( $json ) ) {
237
+ LiteSpeed_Cache_Log::debug( '[CSS] failed to decode post json: ' . $response[ 'body' ] ) ;
238
+ return false ;
239
+ }
240
+
241
+ if ( ! empty( $json[ '_err' ] ) ) {
242
+ LiteSpeed_Cache_Log::debug( '[CSS] _err: ' . $json[ '_err' ] ) ;
243
+ return false ;
244
+ }
245
+
246
+ if ( empty( $json[ 'ccss' ] ) ) {
247
+ LiteSpeed_Cache_Log::debug( '[CSS] empty ccss ' ) ;
248
+ return false ;
249
+ }
250
+
251
+ // Write to file
252
+ Litespeed_File::save( $ccss_file, $json[ 'ccss' ], true ) ;
253
+
254
+ // Save summary data
255
+ $req_summary[ 'last_spent' ] = time() - $req_summary[ 'curr_request' ] ;
256
+ $req_summary[ 'last_request' ] = $req_summary[ 'curr_request' ] ;
257
+ $req_summary[ 'curr_request' ] = 0 ;
258
+ if ( empty( $req_summary[ 'ccss_type_history' ] ) ) {
259
+ $req_summary[ 'ccss_type_history' ] = array() ;
260
+ }
261
+ $req_summary[ 'ccss_type_history' ][ $ccss_type ] = $request_url ;
262
+ unset( $req_summary[ 'queue' ][ $ccss_type ] ) ;
263
+
264
+ $this->_save_summary( $req_summary ) ;
265
+
266
+ LiteSpeed_Cache_Log::debug( '[CSS] saved ccss ' . $ccss_file ) ;
267
+
268
+ LiteSpeed_Cache_Log::debug2( '[CSS] ccss con: ' . $json[ 'ccss' ] ) ;
269
+
270
+ return $json[ 'ccss' ] ;
271
+ }
272
+
273
+ /**
274
+ * The critical css file for current page
275
+ *
276
+ * @since 2.3
277
+ * @access private
278
+ */
279
+ private function _which_css()
280
+ {
281
+ $css = 'default' ;
282
+ if ( is_404() ) {
283
+ $css = '404' ;
284
+ }
285
+ elseif ( is_singular() ) {
286
+ $css = get_post_type() ;
287
+ }
288
+ elseif ( is_home() && get_option( 'show_on_front' ) == 'page' ) {
289
+ $css = 'home' ;
290
+ }
291
+ elseif ( is_front_page() ) {
292
+ $css = 'front' ;
293
+ }
294
+ elseif ( is_tax() ) {
295
+ $css = get_queried_object()->taxonomy ;
296
+ }
297
+ elseif ( is_category() ) {
298
+ $css = 'category' ;
299
+ }
300
+ elseif ( is_tag() ) {
301
+ $css = 'tag' ;
302
+ }
303
+
304
+ return $css ;
305
+ }
306
+
307
+ /**
308
+ * Handle all request actions from main cls
309
+ *
310
+ * @since 2.3
311
+ * @access public
312
+ */
313
+ public static function handler()
314
+ {
315
+ $instance = self::get_instance() ;
316
+
317
+ $type = LiteSpeed_Cache_Router::verify_type() ;
318
+
319
+ switch ( $type ) {
320
+ case self::TYPE_GENERATE_CRITICAL :
321
+ self::cron_ccss( true ) ;
322
+ break ;
323
+
324
+ default:
325
+ break ;
326
+ }
327
+
328
+ LiteSpeed_Cache_Admin::redirect() ;
329
+ }
330
+
331
+ /**
332
+ * Get the current instance object.
333
+ *
334
+ * @since 2.3
335
+ * @access public
336
+ * @return Current class instance.
337
+ */
338
+ public static function get_instance()
339
+ {
340
+ if ( ! isset( self::$_instance ) ) {
341
+ self::$_instance = new self() ;
342
+ }
343
+
344
+ return self::$_instance ;
345
+ }
346
+
347
+ }
inc/gui.class.php CHANGED
@@ -171,6 +171,8 @@ class LiteSpeed_Cache_GUI
171
{
172
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.php" ;
173
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.slack.php" ;
174
}
175
176
/**
@@ -430,6 +432,15 @@ class LiteSpeed_Cache_GUI
430
) );
431
}
432
433
}
434
435
/**
171
{
172
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.php" ;
173
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.slack.php" ;
174
+
175
+ include_once LSCWP_DIR . "admin/tpl/inc/disabled_all.php" ;
176
}
177
178
/**
432
) );
433
}
434
435
+ if ( LiteSpeed_Cache_CSS::has_ccss_cache() ) {
436
+ $wp_admin_bar->add_menu( array(
437
+ 'parent' => 'litespeed-menu',
438
+ 'id' => 'litespeed-purge-ccss',
439
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Critical CSS', 'litespeed-cache' ),
440
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_CCSS ),
441
+ 'meta' => array( 'tabindex' => '0' ),
442
+ ) );
443
+ }
444
}
445
446
/**
inc/litespeed-cache.class.php CHANGED
@@ -19,7 +19,7 @@ class LiteSpeed_Cache
19
private static $_instance ;
20
21
const PLUGIN_NAME = 'litespeed-cache' ;
22
- const PLUGIN_VERSION = '2.2.7' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
@@ -57,6 +57,7 @@ class LiteSpeed_Cache
57
const ACTION_IAPI = 'iapi' ;
58
const ACTION_CDN = 'cdn' ;
59
const ACTION_REPORT = 'report' ;
60
const ACTION_SAPI_PASSIVE_CALLBACK = 'sapi_passive_callback' ;
61
const ACTION_SAPI_AGGRESSIVE_CALLBACK = 'sapi_aggressive_callback' ;
62
@@ -327,6 +328,10 @@ class LiteSpeed_Cache
327
$msg = LiteSpeed_Cache_Import::handler() ;
328
break ;
329
330
case LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE:
331
$msg = LiteSpeed_Cache_CDN_Cloudflare::handler() ;
332
break ;
19
private static $_instance ;
20
21
const PLUGIN_NAME = 'litespeed-cache' ;
22
+ const PLUGIN_VERSION = '2.3.1' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
57
const ACTION_IAPI = 'iapi' ;
58
const ACTION_CDN = 'cdn' ;
59
const ACTION_REPORT = 'report' ;
60
+ const ACTION_CSS = 'css' ;
61
const ACTION_SAPI_PASSIVE_CALLBACK = 'sapi_passive_callback' ;
62
const ACTION_SAPI_AGGRESSIVE_CALLBACK = 'sapi_aggressive_callback' ;
63
328
$msg = LiteSpeed_Cache_Import::handler() ;
329
break ;
330
331
+ case LiteSpeed_Cache::ACTION_CSS:
332
+ $msg = LiteSpeed_Cache_CSS::handler() ;
333
+ break ;
334
+
335
case LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE:
336
$msg = LiteSpeed_Cache_CDN_Cloudflare::handler() ;
337
break ;
inc/litespeed.autoload.php CHANGED
@@ -32,6 +32,7 @@ if ( !function_exists('_litespeed_autoload') ) {
32
'LiteSpeed_Cache_Control' => 'inc/control.class.php',
33
'LiteSpeed_Cache_Crawler' => 'inc/crawler.class.php',
34
'LiteSpeed_Cache_Crawler_Sitemap' => 'inc/crawler-sitemap.class.php',
35
'LiteSpeed_Cache_Data' => 'inc/data.class.php',
36
'LiteSpeed_Cache_Doc' => 'inc/doc.cls.php',
37
'LiteSpeed_Cache_ESI' => 'inc/esi.class.php',
32
'LiteSpeed_Cache_Control' => 'inc/control.class.php',
33
'LiteSpeed_Cache_Crawler' => 'inc/crawler.class.php',
34
'LiteSpeed_Cache_Crawler_Sitemap' => 'inc/crawler-sitemap.class.php',
35
+ 'LiteSpeed_Cache_CSS' => 'inc/css.cls.php',
36
'LiteSpeed_Cache_Data' => 'inc/data.class.php',
37
'LiteSpeed_Cache_Doc' => 'inc/doc.cls.php',
38
'LiteSpeed_Cache_ESI' => 'inc/esi.class.php',
inc/log.class.php CHANGED
@@ -235,17 +235,23 @@ class LiteSpeed_Cache_Log
235
if ( defined( 'LSCWP_LOG_MORE' ) && $backtrace_limit !== false ) {
236
$trace = version_compare( PHP_VERSION, '5.4.0', '<' ) ? debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $backtrace_limit + 2 ) ;
237
for ( $i=1 ; $i <= $backtrace_limit + 1 ; $i++ ) {// the 0st item is push()
238
- if ( empty( $trace[$i]['class'] ) ) {
239
- break ;
240
}
241
- if ( $trace[$i]['class'] == 'LiteSpeed_Cache_Log' ) {
242
- continue ;
243
}
244
- $log = str_replace('LiteSpeed_Cache', 'LSC', $trace[$i]['class']) . $trace[$i]['type'] . $trace[$i]['function'] . '()' ;
245
if ( ! empty( $trace[$i-1]['line'] ) ) {
246
$log .= '@' . $trace[$i-1]['line'] ;
247
}
248
- $msg .= " \ $log" ;
249
}
250
251
}
235
if ( defined( 'LSCWP_LOG_MORE' ) && $backtrace_limit !== false ) {
236
$trace = version_compare( PHP_VERSION, '5.4.0', '<' ) ? debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $backtrace_limit + 2 ) ;
237
for ( $i=1 ; $i <= $backtrace_limit + 1 ; $i++ ) {// the 0st item is push()
238
+ if ( empty( $trace[ $i ][ 'class' ] ) ) {
239
+ if ( empty( $trace[ $i ][ 'file' ] ) ) {
240
+ break ;
241
+ }
242
+ $log = "\n" . $trace[ $i ][ 'file' ] ;
243
}
244
+ else {
245
+ if ( $trace[$i]['class'] == 'LiteSpeed_Cache_Log' ) {
246
+ continue ;
247
+ }
248
+
249
+ $log = str_replace('LiteSpeed_Cache', 'LSC', $trace[$i]['class']) . $trace[$i]['type'] . $trace[$i]['function'] . '()' ;
250
}
251
if ( ! empty( $trace[$i-1]['line'] ) ) {
252
$log .= '@' . $trace[$i-1]['line'] ;
253
}
254
+ $msg .= " => $log" ;
255
}
256
257
}
inc/optimize.class.php CHANGED
@@ -16,6 +16,7 @@ class LiteSpeed_Cache_Optimize
16
17
const DIR_MIN = '/min' ;
18
const CSS_ASYNC_LIB = '/min/css_async.js' ;
19
20
private $content ;
21
private $http2_headers = array() ;
@@ -74,7 +75,7 @@ class LiteSpeed_Cache_Optimize
74
75
$this->_static_request_check() ;
76
77
- if ( ! $this->_can_optm() ) {
78
return ;
79
}
80
@@ -90,7 +91,7 @@ class LiteSpeed_Cache_Optimize
90
91
// Check if there is any critical css rules setting
92
if ( $this->cfg_css_async ) {
93
- add_action( 'wp_head', array( $this, 'prepend_critical_css' ), 1 ) ;
94
}
95
96
/**
@@ -154,24 +155,6 @@ class LiteSpeed_Cache_Optimize
154
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ) ;
155
}
156
157
- /**
158
- * Output critical css
159
- *
160
- * @since 1.3
161
- * @access public
162
- * @return string The static file content
163
- */
164
- public function prepend_critical_css()
165
- {
166
-
167
- $rules = get_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS ) ;
168
- if ( ! $rules ) {
169
- return ;
170
- }
171
-
172
- echo '<style id="litespeed-optm-css-rules">' . $rules . '</style>' ;
173
- }
174
-
175
/**
176
* Check if the request is for static file
177
*
@@ -185,9 +168,7 @@ class LiteSpeed_Cache_Optimize
185
if ( ( $this->cfg_css_async || $this->cfg_ggfonts_async ) && strpos( $_SERVER[ 'REQUEST_URI' ], self::CSS_ASYNC_LIB ) !== false ) {
186
LiteSpeed_Cache_Log::debug( '[Optm] start serving static file' ) ;
187
188
- $file = LSCWP_DIR . 'js/css_async.min.js' ;
189
-
190
- $content = Litespeed_File::read( $file ) ;
191
192
$static_file = LSCWP_CONTENT_DIR . '/cache/js/css_async.js' ;
193
@@ -318,33 +299,6 @@ class LiteSpeed_Cache_Optimize
318
return $src ;
319
}
320
321
- /**
322
- * Check if can run optimize
323
- *
324
- * @since 1.3
325
- * @access private
326
- */
327
- private function _can_optm()
328
- {
329
- if ( is_admin() ) {
330
- return false ;
331
- }
332
-
333
- if ( is_feed() ) {
334
- return false ;
335
- }
336
-
337
- if ( is_preview() ) {
338
- return false ;
339
- }
340
-
341
- if ( LiteSpeed_Cache_Router::is_ajax() ) {
342
- return false ;
343
- }
344
-
345
- return true ;
346
- }
347
-
348
/**
349
* Run optimize process
350
* NOTE: As this is after cache finalized, can NOT set any cache control anymore
@@ -365,9 +319,9 @@ class LiteSpeed_Cache_Optimize
365
}
366
367
// Check if hit URI excludes
368
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES ) ;
369
if ( ! empty( $excludes ) ) {
370
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
371
if ( $result ) {
372
LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
373
return $content ;
@@ -398,7 +352,7 @@ class LiteSpeed_Cache_Optimize
398
*/
399
private function _optimize()
400
{
401
- if ( ! $this->_can_optm() ) {
402
LiteSpeed_Cache_Log::debug( '[Optm] bypass: admin/feed/preview' ) ;
403
return ;
404
}
@@ -636,9 +590,15 @@ class LiteSpeed_Cache_Optimize
636
637
// Append async compatibility lib to head
638
if ( $this->cfg_css_async || $this->cfg_ggfonts_async ) {
639
- $css_async_lib_url = LiteSpeed_Cache_Utility::get_permalink_url( self::CSS_ASYNC_LIB ) ;
640
- $this->html_head .= "<script src='" . $css_async_lib_url . "' " . ( $this->cfg_js_defer ? 'defer' : '' ) . "></script>" ;// Don't exclude it from defer for now
641
- $this->append_http2( $css_async_lib_url, 'js' ) ; // async lib will be http/2 pushed always
642
}
643
644
if ( $this->cfg_ggfonts_async ) {
@@ -1226,6 +1186,3 @@ class LiteSpeed_Cache_Optimize
1226
}
1227
1228
}
1229
-
1230
-
1231
-
16
17
const DIR_MIN = '/min' ;
18
const CSS_ASYNC_LIB = '/min/css_async.js' ;
19
+ const CSS_ASYNC_LIB_FILE = 'js/css_async.min.js' ;
20
21
private $content ;
22
private $http2_headers = array() ;
75
76
$this->_static_request_check() ;
77
78
+ if ( ! LiteSpeed_Cache_Router::can_optm() ) {
79
return ;
80
}
81
91
92
// Check if there is any critical css rules setting
93
if ( $this->cfg_css_async ) {
94
+ add_filter( 'litespeed_optm_html_head', 'LiteSpeed_Cache_CSS::prepend_ccss', 1 ) ;
95
}
96
97
/**
155
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ) ;
156
}
157
158
/**
159
* Check if the request is for static file
160
*
168
if ( ( $this->cfg_css_async || $this->cfg_ggfonts_async ) && strpos( $_SERVER[ 'REQUEST_URI' ], self::CSS_ASYNC_LIB ) !== false ) {
169
LiteSpeed_Cache_Log::debug( '[Optm] start serving static file' ) ;
170
171
+ $content = Litespeed_File::read( LSCWP_DIR . self::CSS_ASYNC_LIB_FILE ) ;
172
173
$static_file = LSCWP_CONTENT_DIR . '/cache/js/css_async.js' ;
174
299
return $src ;
300
}
301
302
/**
303
* Run optimize process
304
* NOTE: As this is after cache finalized, can NOT set any cache control anymore
319
}
320
321
// Check if hit URI excludes
322
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_OPTM_EXCLUDES ) ;
323
if ( ! empty( $excludes ) ) {
324
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
325
if ( $result ) {
326
LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
327
return $content ;
352
*/
353
private function _optimize()
354
{
355
+ if ( ! LiteSpeed_Cache_Router::can_optm() ) {
356
LiteSpeed_Cache_Log::debug( '[Optm] bypass: admin/feed/preview' ) ;
357
return ;
358
}
590
591
// Append async compatibility lib to head
592
if ( $this->cfg_css_async || $this->cfg_ggfonts_async ) {
593
+ // Inline css async lib
594
+ if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPT_OPTM_CSS_ASYNC_INLINE ) ) {
595
+ $this->html_head .= '<script id="litespeed-css-async-lib" type="text/javascript">' . Litespeed_File::read( LSCWP_DIR . self::CSS_ASYNC_LIB_FILE ) . '</script>' ;
596
+ }
597
+ else {
598
+ $css_async_lib_url = LiteSpeed_Cache_Utility::get_permalink_url( self::CSS_ASYNC_LIB ) ;
599
+ $this->html_head .= "<script id='litespeed-css-async-lib' src='" . $css_async_lib_url . "' " . ( $this->cfg_js_defer ? 'defer' : '' ) . "></script>" ;// Don't exclude it from defer for now
600
+ $this->append_http2( $css_async_lib_url, 'js' ) ; // async lib will be http/2 pushed always
601
+ }
602
}
603
604
if ( $this->cfg_ggfonts_async ) {
1186
}
1187
1188
}
inc/purge.class.php CHANGED
@@ -23,6 +23,7 @@ class LiteSpeed_Cache_Purge
23
const TYPE_PURGE_ALL = 'purge_all' ;
24
const TYPE_PURGE_ALL_LSCACHE = 'purge_all_lscache' ;
25
const TYPE_PURGE_ALL_CSSJS = 'purge_all_cssjs' ;
26
const TYPE_PURGE_ALL_OBJECT = 'purge_all_object' ;
27
const TYPE_PURGE_ALL_OPCACHE = 'purge_all_opcache' ;
28
@@ -81,6 +82,10 @@ class LiteSpeed_Cache_Purge
81
$instance->_purge_all_cssjs() ;
82
break ;
83
84
case self::TYPE_PURGE_ALL_OBJECT :
85
$instance->_purge_all_object() ;
86
break ;
@@ -133,6 +138,7 @@ class LiteSpeed_Cache_Purge
133
{
134
$this->_purge_all_lscache( true ) ;
135
$this->_purge_all_cssjs( true ) ;
136
$this->_purge_all_object( true ) ;
137
$this->_purge_all_opcache( true ) ;
138
@@ -174,6 +180,22 @@ class LiteSpeed_Cache_Purge
174
}
175
}
176
177
/**
178
* Alerts LiteSpeed Web Server to purge pages.
179
*
23
const TYPE_PURGE_ALL = 'purge_all' ;
24
const TYPE_PURGE_ALL_LSCACHE = 'purge_all_lscache' ;
25
const TYPE_PURGE_ALL_CSSJS = 'purge_all_cssjs' ;
26
+ const TYPE_PURGE_ALL_CCSS = 'purge_all_ccss' ;
27
const TYPE_PURGE_ALL_OBJECT = 'purge_all_object' ;
28
const TYPE_PURGE_ALL_OPCACHE = 'purge_all_opcache' ;
29
82
$instance->_purge_all_cssjs() ;
83
break ;
84
85
+ case self::TYPE_PURGE_ALL_CCSS :
86
+ $instance->_purge_all_ccss() ;
87
+ break ;
88
+
89
case self::TYPE_PURGE_ALL_OBJECT :
90
$instance->_purge_all_object() ;
91
break ;
138
{
139
$this->_purge_all_lscache( true ) ;
140
$this->_purge_all_cssjs( true ) ;
141
+ $this->_purge_all_ccss( true ) ;
142
$this->_purge_all_object( true ) ;
143
$this->_purge_all_opcache( true ) ;
144
180
}
181
}
182
183
+ /**
184
+ * Delete all critical css
185
+ *
186
+ * @since 2.3
187
+ * @access private
188
+ */
189
+ private function _purge_all_ccss( $silence = false )
190
+ {
191
+ LiteSpeed_Cache_CSS::get_instance()->rm_cache_folder() ;
192
+
193
+ if ( ! $silence ) {
194
+ $msg = __( 'Cleaned all critical CSS files.', 'litespeed-cache' ) ;
195
+ ! defined( 'LITESPEED_PURGE_SILENT' ) && LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
196
+ }
197
+ }
198
+
199
/**
200
* Alerts LiteSpeed Web Server to purge pages.
201
*
inc/router.class.php CHANGED
@@ -14,6 +14,7 @@
14
class LiteSpeed_Cache_Router
15
{
16
private static $_instance ;
17
private static $_esi_enabled ;
18
private static $_is_ajax ;
19
private static $_is_logged_in ;
@@ -23,6 +24,103 @@ class LiteSpeed_Cache_Router
23
private static $_is_admin_ip ;
24
private static $_frontend_path ;
25
26
/**
27
* Crawler simulate role
28
*
@@ -385,6 +483,8 @@ class LiteSpeed_Cache_Router
385
case LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE:
386
case LiteSpeed_Cache::ACTION_CDN_QUICCLOUD:
387
case LiteSpeed_Cache::ACTION_IMPORT:
388
if ( $_can_option && ! $_is_network_admin ) {
389
self::$_action = $action ;
390
}
@@ -396,12 +496,6 @@ class LiteSpeed_Cache_Router
396
}
397
return ;
398
399
- case LiteSpeed_Cache::ACTION_REPORT:
400
- if ( $_can_option && ! $_is_network_admin ) {
401
- self::$_action = $action ;
402
- }
403
- return ;
404
-
405
case LiteSpeed_Cache::ACTION_SAPI_PASSIVE_CALLBACK :
406
case LiteSpeed_Cache::ACTION_SAPI_AGGRESSIVE_CALLBACK :
407
self::$_action = $action ;
14
class LiteSpeed_Cache_Router
15
{
16
private static $_instance ;
17
+
18
private static $_esi_enabled ;
19
private static $_is_ajax ;
20
private static $_is_logged_in ;
24
private static $_is_admin_ip ;
25
private static $_frontend_path ;
26
27
+ /**
28
+ * Check if can run optimize
29
+ *
30
+ * @since 1.3
31
+ * @since 2.3.1 Relocated from cdn.cls
32
+ * @access public
33
+ */
34
+ public static function can_optm()
35
+ {
36
+ $can = true ;
37
+
38
+ if ( is_admin() ) {
39
+ $can = false ;
40
+ }
41
+
42
+ if ( is_feed() ) {
43
+ $can = false ;
44
+ }
45
+
46
+ if ( is_preview() ) {
47
+ $can = false ;
48
+ }
49
+
50
+ if ( self::is_ajax() ) {
51
+ $can = false ;
52
+ }
53
+
54
+ if ( self::_is_login_page() ) {
55
+ LiteSpeed_Cache_Log::debug( '[Router] Optm bypassed: login/reg page' ) ;
56
+ $can = false ;
57
+ }
58
+
59
+ $can_final = apply_filters( 'litespeed_can_optm', $can ) ;
60
+
61
+ if ( $can_final != $can ) {
62
+ LiteSpeed_Cache_Log::debug( '[Router] Optm bypassed: filter' ) ;
63
+ }
64
+
65
+ return $can_final ;
66
+ }
67
+
68
+ /**
69
+ * Check if it can use CDN replacement
70
+ *
71
+ * @since 1.2.3
72
+ * @since 2.3.1 Relocated from cdn.cls
73
+ * @access public
74
+ */
75
+ public static function can_cdn()
76
+ {
77
+ $can = true ;
78
+
79
+ if ( is_admin() && ! self::is_ajax() ) {
80
+ $can = false ;
81
+ }
82
+
83
+ if ( is_feed() ) {
84
+ $can = false ;
85
+ }
86
+
87
+ if ( is_preview() ) {
88
+ $can = false ;
89
+ }
90
+
91
+ /**
92
+ * Bypass login/reg page
93
+ * @since 1.6
94
+ */
95
+ if ( self::_is_login_page() ) {
96
+ LiteSpeed_Cache_Log::debug( '[Router] CDN bypassed: login/reg page' ) ;
97
+ $can = false ;
98
+ }
99
+
100
+ $can_final = apply_filters( 'litespeed_can_cdn', $can ) ;
101
+
102
+ if ( $can_final != $can ) {
103
+ LiteSpeed_Cache_Log::debug( '[Router] CDN bypassed: filter' ) ;
104
+ }
105
+
106
+ return $can_final ;
107
+ }
108
+
109
+ /**
110
+ * Check if is login page or not
111
+ *
112
+ * @since 2.3.1
113
+ * @access protected
114
+ */
115
+ protected static function _is_login_page()
116
+ {
117
+ if ( in_array( $GLOBALS[ 'pagenow' ], array( 'wp-login.php', 'wp-register.php' ), true ) ) {
118
+ return true ;
119
+ }
120
+
121
+ return false ;
122
+ }
123
+
124
/**
125
* Crawler simulate role
126
*
483
case LiteSpeed_Cache::ACTION_CDN_CLOUDFLARE:
484
case LiteSpeed_Cache::ACTION_CDN_QUICCLOUD:
485
case LiteSpeed_Cache::ACTION_IMPORT:
486
+ case LiteSpeed_Cache::ACTION_REPORT:
487
+ case LiteSpeed_Cache::ACTION_CSS:
488
if ( $_can_option && ! $_is_network_admin ) {
489
self::$_action = $action ;
490
}
496
}
497
return ;
498
499
case LiteSpeed_Cache::ACTION_SAPI_PASSIVE_CALLBACK :
500
case LiteSpeed_Cache::ACTION_SAPI_AGGRESSIVE_CALLBACK :
501
self::$_action = $action ;
inc/task.class.php CHANGED
@@ -15,8 +15,9 @@ class LiteSpeed_Cache_Task
15
16
const CRON_ACTION_HOOK_CRAWLER = 'litespeed_crawl_trigger' ;
17
const CRON_ACTION_HOOK_IMGOPTM = 'litespeed_imgoptm_trigger' ;
18
const CRON_FITLER_CRAWLER = 'litespeed_crawl_filter' ;
19
- const CRON_FITLER_IMGOPTM = 'litespeed_imgoptm_filter' ;
20
21
/**
22
* Init
@@ -46,6 +47,13 @@ class LiteSpeed_Cache_Task
46
else {
47
// wp_clear_scheduled_hook( self::CRON_ACTION_HOOK_IMGOPTM ) ;
48
}
49
}
50
51
/**
@@ -104,12 +112,29 @@ class LiteSpeed_Cache_Task
104
*/
105
public static function schedule_filter_imgoptm()
106
{
107
- add_filter( 'cron_schedules', 'LiteSpeed_Cache_Task::lscache_cron_filter_imgoptm' ) ;
108
109
// Schedule event here to see if it can lost again or not
110
if( ! wp_next_scheduled( self::CRON_ACTION_HOOK_IMGOPTM ) ) {
111
LiteSpeed_Cache_Log::debug( 'Cron log: ......img optimization cron hook register......' ) ;
112
- wp_schedule_event( time(), self::CRON_FITLER_IMGOPTM, self::CRON_ACTION_HOOK_IMGOPTM ) ;
113
}
114
}
115
@@ -137,12 +162,12 @@ class LiteSpeed_Cache_Task
137
* @access public
138
* @param array $schedules WP Hook
139
*/
140
- public static function lscache_cron_filter_imgoptm( $schedules )
141
{
142
- if ( ! array_key_exists( self::CRON_FITLER_IMGOPTM, $schedules ) ) {
143
- $schedules[ self::CRON_FITLER_IMGOPTM ] = array(
144
'interval' => 60,
145
- 'display' => __( 'LiteSpeed Cache Custom Cron ImgOptm', 'litespeed-cache' ),
146
) ;
147
}
148
return $schedules ;
15
16
const CRON_ACTION_HOOK_CRAWLER = 'litespeed_crawl_trigger' ;
17
const CRON_ACTION_HOOK_IMGOPTM = 'litespeed_imgoptm_trigger' ;
18
+ const CRON_ACTION_HOOK_CCSS = 'litespeed_ccss_trigger' ;
19
const CRON_FITLER_CRAWLER = 'litespeed_crawl_filter' ;
20
+ const CRON_FITLER = 'litespeed_filter' ;
21
22
/**
23
* Init
47
else {
48
// wp_clear_scheduled_hook( self::CRON_ACTION_HOOK_IMGOPTM ) ;
49
}
50
+
51
+ // Register ccss generation
52
+ if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPT_OPTM_CCSS_ASYNC ) && LiteSpeed_Cache_CSS::has_queue() ) {
53
+ self::schedule_filter_ccss() ;
54
+
55
+ add_action( self::CRON_ACTION_HOOK_CCSS, 'LiteSpeed_Cache_CSS::cron_ccss' ) ;
56
+ }
57
}
58
59
/**
112
*/
113
public static function schedule_filter_imgoptm()
114
{
115
+ add_filter( 'cron_schedules', 'LiteSpeed_Cache_Task::lscache_cron_filter' ) ;
116
117
// Schedule event here to see if it can lost again or not
118
if( ! wp_next_scheduled( self::CRON_ACTION_HOOK_IMGOPTM ) ) {
119
LiteSpeed_Cache_Log::debug( 'Cron log: ......img optimization cron hook register......' ) ;
120
+ wp_schedule_event( time(), self::CRON_FITLER, self::CRON_ACTION_HOOK_IMGOPTM ) ;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Schedule cron ccss generation
126
+ *
127
+ * @since 2.3
128
+ * @access public
129
+ */
130
+ public static function schedule_filter_ccss()
131
+ {
132
+ add_filter( 'cron_schedules', 'LiteSpeed_Cache_Task::lscache_cron_filter' ) ;
133
+
134
+ // Schedule event here to see if it can lost again or not
135
+ if( ! wp_next_scheduled( self::CRON_ACTION_HOOK_CCSS ) ) {
136
+ LiteSpeed_Cache_Log::debug( 'Cron log: ......ccss cron hook register......' ) ;
137
+ wp_schedule_event( time(), self::CRON_FITLER, self::CRON_ACTION_HOOK_CCSS ) ;
138
}
139
}
140
162
* @access public
163
* @param array $schedules WP Hook
164
*/
165
+ public static function lscache_cron_filter( $schedules )
166
{
167
+ if ( ! array_key_exists( self::CRON_FITLER, $schedules ) ) {
168
+ $schedules[ self::CRON_FITLER ] = array(
169
'interval' => 60,
170
+ 'display' => __( 'LiteSpeed Cache Custom Cron Common', 'litespeed-cache' ),
171
) ;
172
}
173
return $schedules ;
inc/utility.class.php CHANGED
@@ -306,13 +306,16 @@ class LiteSpeed_Cache_Utility
306
* @param bool $type String handler type
307
* @return string
308
*/
309
- public static function sanitize_lines( $content, $type = null )
310
{
311
- if ( ! $content ) {
312
- return $content ;
313
}
314
315
- $arr = explode( "\n", $content ) ;
316
$arr = array_map( 'trim', $arr ) ;
317
if ( $type === 'uri' ) {
318
$arr = array_map( 'LiteSpeed_Cache_Utility::url2uri', $arr ) ;
306
* @param bool $type String handler type
307
* @return string
308
*/
309
+ public static function sanitize_lines( $arr, $type = null )
310
{
311
+ if ( ! $arr ) {
312
+ return $arr ;
313
+ }
314
+
315
+ if ( ! is_array( $arr ) ) {
316
+ $arr = explode( "\n", $arr ) ;
317
}
318
319
$arr = array_map( 'trim', $arr ) ;
320
if ( $type === 'uri' ) {
321
$arr = array_map( 'LiteSpeed_Cache_Utility::url2uri', $arr ) ;
includes/litespeed-cache-cdn.class.php CHANGED
@@ -37,7 +37,7 @@ class LiteSpeed_Cache_CDN
37
{
38
LiteSpeed_Cache_Log::debug2( 'CDN init' ) ;
39
40
- if ( ! $this->can_cdn() ) {
41
if ( ! defined( self::BYPASS ) ) {
42
define( self::BYPASS, true ) ;
43
}
@@ -235,38 +235,6 @@ class LiteSpeed_Cache_CDN
235
return $instance->content ;
236
}
237
238
- /**
239
- * Check if it can use CDN replacement
240
- *
241
- * @since 1.2.3
242
- * @access public
243
- */
244
- public function can_cdn()
245
- {
246
- if ( is_admin() ) {
247
- return false ;
248
- }
249
-
250
- if ( is_feed() ) {
251
- return false ;
252
- }
253
-
254
- if ( is_preview() ) {
255
- return false ;
256
- }
257
-
258
- /**
259
- * Bypass login/reg page
260
- * @since 1.6
261
- */
262
- if ( in_array( $GLOBALS[ 'pagenow' ], array( 'wp-login.php', 'wp-register.php' ), true ) ) {
263
- LiteSpeed_Cache_Log::debug( 'CDN bypassed as is login/reg page' ) ;
264
- return false ;
265
- }
266
-
267
- return true ;
268
- }
269
-
270
/**
271
* Replace CDN url
272
*
37
{
38
LiteSpeed_Cache_Log::debug2( 'CDN init' ) ;
39
40
+ if ( ! LiteSpeed_Cache_Router::can_cdn() ) {
41
if ( ! defined( self::BYPASS ) ) {
42
define( self::BYPASS, true ) ;
43
}
235
return $instance->content ;
236
}
237
238
/**
239
* Replace CDN url
240
*
includes/litespeed-cache-config.class.php CHANGED
@@ -35,6 +35,10 @@ class LiteSpeed_Cache_Config
35
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
36
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
37
const ITEM_MEDIA_WEBP_ATTRIBUTE = 'litespeed-media-webp_attribute' ;
38
39
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
40
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
@@ -73,7 +77,6 @@ class LiteSpeed_Cache_Config
73
const OPID_CACHE_RES = 'cache_resources' ;
74
const OPID_CACHE_MOBILE = 'mobileview_enabled' ;
75
const ID_MOBILEVIEW_LIST = 'mobileview_rules' ;
76
- const OPID_CACHE_URI_PRIV = 'cache_uri_priv' ;
77
const OPID_CACHE_OBJECT = 'cache_object' ;
78
const OPID_CACHE_OBJECT_KIND = 'cache_object_kind' ;
79
const OPID_CACHE_OBJECT_HOST = 'cache_object_host' ;
@@ -130,8 +133,7 @@ class LiteSpeed_Cache_Config
130
const PURGE_DATE = 'D' ;
131
const PURGE_TERM = 'T' ; // include category|tag|tax
132
const PURGE_POST_TYPE = 'PT' ;
133
- const OPID_FORCE_CACHE_URI = 'forced_cache_uri' ;
134
- const OPID_EXCLUDES_URI = 'excludes_uri' ;
135
const OPID_EXCLUDES_QS = 'excludes_qs' ;
136
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
137
const OPID_EXCLUDES_TAG = 'excludes_tag' ;
@@ -156,9 +158,11 @@ class LiteSpeed_Cache_Config
156
const OPID_OPTM_QS_RM = 'optm_qs_rm' ;
157
const OPID_OPTM_GGFONTS_RM = 'optm_ggfonts_rm' ;
158
const OPID_OPTM_CSS_ASYNC = 'optm_css_async' ;
159
const OPID_OPTM_JS_DEFER = 'optm_js_defer' ;
160
const OPID_OPTM_EMOJI_RM = 'optm_emoji_rm' ;
161
- const OPID_OPTM_EXCLUDES = 'optm_excludes' ;
162
const OPID_OPTM_EXC_JQUERY = 'optm_exclude_jquery' ;
163
const OPID_OPTM_GGFONTS_ASYNC = 'optm_ggfonts_async' ;
164
const OPID_OPTM_MAX_SIZE = 'optm_max_size' ;
@@ -293,6 +297,10 @@ class LiteSpeed_Cache_Config
293
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
294
self::ITEM_CRWL_AS_UIDS,
295
self::ITEM_ADV_PURGE_ALL_HOOKS,
296
) ;
297
}
298
@@ -456,20 +464,20 @@ class LiteSpeed_Cache_Config
456
457
switch ( $type ) {
458
case 'forced_cache' :
459
- $id = self::OPID_FORCE_CACHE_URI ;
460
break ;
461
462
case 'private' :
463
- $id = self::OPID_CACHE_URI_PRIV ;
464
break ;
465
466
case 'nonoptimize' :
467
- $id = self::OPID_OPTM_EXCLUDES ;
468
break ;
469
470
case 'nocache' :
471
default:
472
- $id = self::OPID_EXCLUDES_URI ;
473
break ;
474
}
475
@@ -477,12 +485,9 @@ class LiteSpeed_Cache_Config
477
$list = $instance->get_item( $id ) ;
478
479
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
480
- $list = array_map( 'LiteSpeed_Cache_Utility::make_relative', $list ) ;// Remove domain
481
- $list = array_unique( $list ) ;
482
- $list = array_filter( $list ) ;
483
- $list = implode( "\n", $list ) ;
484
485
- $instance->update_options( array( $id => $list ) ) ;
486
487
// Purge this page & redirect
488
LiteSpeed_Cache_Purge::purge_front() ;
@@ -627,7 +632,6 @@ class LiteSpeed_Cache_Config
627
self::OPID_CACHE_RES => true,
628
self::OPID_CACHE_MOBILE => false,
629
self::ID_MOBILEVIEW_LIST => false,
630
- self::OPID_CACHE_URI_PRIV => '',
631
self::OPID_CACHE_OBJECT => false,
632
self::OPID_CACHE_OBJECT_KIND => false,
633
self::OPID_CACHE_OBJECT_HOST => 'localhost',
@@ -662,8 +666,6 @@ class LiteSpeed_Cache_Config
662
self::OPID_404_TTL => 3600,
663
self::OPID_500_TTL => 3600,
664
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
665
- self::OPID_FORCE_CACHE_URI => '',
666
- self::OPID_EXCLUDES_URI => '',
667
self::OPID_EXCLUDES_QS => '',
668
self::OPID_EXCLUDES_CAT => '',
669
self::OPID_EXCLUDES_TAG => '',
@@ -688,9 +690,11 @@ class LiteSpeed_Cache_Config
688
self::OPID_OPTM_QS_RM => false,
689
self::OPID_OPTM_GGFONTS_RM => false,
690
self::OPID_OPTM_CSS_ASYNC => false,
691
self::OPID_OPTM_JS_DEFER => false,
692
self::OPID_OPTM_EMOJI_RM => false,
693
- self::OPID_OPTM_EXCLUDES => '',
694
self::OPID_OPTM_EXC_JQUERY => true,
695
self::OPID_OPTM_GGFONTS_ASYNC => false,
696
self::OPID_OPTM_MAX_SIZE => 1.2,
@@ -996,6 +1000,23 @@ class LiteSpeed_Cache_Config
996
LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
997
}
998
999
$this->options = self::option_diff( $default_options, $this->options ) ;
1000
1001
$res = $this->update_options() ;
35
const ITEM_ADV_PURGE_ALL_HOOKS = 'litespeed-adv-purge_all_hooks' ;
36
const ITEM_CDN_ORI_DIR = 'litespeed-cdn-ori_dir' ;
37
const ITEM_MEDIA_WEBP_ATTRIBUTE = 'litespeed-media-webp_attribute' ;
38
+ const ITEM_FORCE_CACHE_URI = 'litespeed-forced_cache_uri' ;
39
+ const ITEM_CACHE_URI_PRIV = 'litespeed-cache_uri_priv' ;
40
+ const ITEM_OPTM_EXCLUDES = 'litespeed-optm_excludes' ;
41
+ const ITEM_EXCLUDES_URI = 'litespeed-excludes_uri' ;
42
43
const ITEM_SETTING_MODE = 'litespeed-setting-mode' ;
44
const ITEM_CRAWLER_HASH = 'litespeed-crawler-hash' ;
77
const OPID_CACHE_RES = 'cache_resources' ;
78
const OPID_CACHE_MOBILE = 'mobileview_enabled' ;
79
const ID_MOBILEVIEW_LIST = 'mobileview_rules' ;
80
const OPID_CACHE_OBJECT = 'cache_object' ;
81
const OPID_CACHE_OBJECT_KIND = 'cache_object_kind' ;
82
const OPID_CACHE_OBJECT_HOST = 'cache_object_host' ;
133
const PURGE_DATE = 'D' ;
134
const PURGE_TERM = 'T' ; // include category|tag|tax
135
const PURGE_POST_TYPE = 'PT' ;
136
+
137
const OPID_EXCLUDES_QS = 'excludes_qs' ;
138
const OPID_EXCLUDES_CAT = 'excludes_cat' ;
139
const OPID_EXCLUDES_TAG = 'excludes_tag' ;
158
const OPID_OPTM_QS_RM = 'optm_qs_rm' ;
159
const OPID_OPTM_GGFONTS_RM = 'optm_ggfonts_rm' ;
160
const OPID_OPTM_CSS_ASYNC = 'optm_css_async' ;
161
+ const OPT_OPTM_CCSS_GEN = 'optm_ccss_gen' ;
162
+ const OPT_OPTM_CCSS_ASYNC = 'optm_ccss_async' ;
163
+ const OPT_OPTM_CSS_ASYNC_INLINE = 'optm_css_async_inline' ;
164
const OPID_OPTM_JS_DEFER = 'optm_js_defer' ;
165
const OPID_OPTM_EMOJI_RM = 'optm_emoji_rm' ;
166
const OPID_OPTM_EXC_JQUERY = 'optm_exclude_jquery' ;
167
const OPID_OPTM_GGFONTS_ASYNC = 'optm_ggfonts_async' ;
168
const OPID_OPTM_MAX_SIZE = 'optm_max_size' ;
297
self::ITEM_OBJECT_NON_PERSISTENT_GROUPS,
298
self::ITEM_CRWL_AS_UIDS,
299
self::ITEM_ADV_PURGE_ALL_HOOKS,
300
+ self::ITEM_FORCE_CACHE_URI,
301
+ self::ITEM_CACHE_URI_PRIV,
302
+ self::ITEM_OPTM_EXCLUDES,
303
+ self::ITEM_EXCLUDES_URI,
304
) ;
305
}
306
464
465
switch ( $type ) {
466
case 'forced_cache' :
467
+ $id = self::ITEM_FORCE_CACHE_URI ;
468
break ;
469
470
case 'private' :
471
+ $id = self::ITEM_CACHE_URI_PRIV ;
472
break ;
473
474
case 'nonoptimize' :
475
+ $id = self::ITEM_OPTM_EXCLUDES ;
476
break ;
477
478
case 'nocache' :
479
default:
480
+ $id = self::ITEM_EXCLUDES_URI ;
481
break ;
482
}
483
485
$list = $instance->get_item( $id ) ;
486
487
$list[] = $_SERVER[ 'HTTP_REFERER' ] ;
488
+ $list = LiteSpeed_Cache_Utility::sanitize_lines( $list, 'relative' ) ;
489
490
+ update_option( $id, $list ) ;
491
492
// Purge this page & redirect
493
LiteSpeed_Cache_Purge::purge_front() ;
632
self::OPID_CACHE_RES => true,
633
self::OPID_CACHE_MOBILE => false,
634
self::ID_MOBILEVIEW_LIST => false,
635
self::OPID_CACHE_OBJECT => false,
636
self::OPID_CACHE_OBJECT_KIND => false,
637
self::OPID_CACHE_OBJECT_HOST => 'localhost',
666
self::OPID_404_TTL => 3600,
667
self::OPID_500_TTL => 3600,
668
self::OPID_PURGE_BY_POST => implode('.', $default_purge_options),
669
self::OPID_EXCLUDES_QS => '',
670
self::OPID_EXCLUDES_CAT => '',
671
self::OPID_EXCLUDES_TAG => '',
690
self::OPID_OPTM_QS_RM => false,
691
self::OPID_OPTM_GGFONTS_RM => false,
692
self::OPID_OPTM_CSS_ASYNC => false,
693
+ self::OPT_OPTM_CCSS_GEN => true,
694
+ self::OPT_OPTM_CCSS_ASYNC => true,
695
+ self::OPT_OPTM_CSS_ASYNC_INLINE => true,
696
self::OPID_OPTM_JS_DEFER => false,
697
self::OPID_OPTM_EMOJI_RM => false,
698
self::OPID_OPTM_EXC_JQUERY => true,
699
self::OPID_OPTM_GGFONTS_ASYNC => false,
700
self::OPID_OPTM_MAX_SIZE => 1.2,
1000
LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
1001
}
1002
1003
+ /**
1004
+ * Move Exclude settings to separate item
1005
+ * @since 2.3
1006
+ */
1007
+ if ( isset( $this->options[ 'forced_cache_uri' ] ) ) {
1008
+ update_option( LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI, $this->options[ 'forced_cache_uri' ] ) ;
1009
+ }
1010
+ if ( isset( $this->options[ 'cache_uri_priv' ] ) ) {
1011
+ update_option( LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV, $this->options[ 'cache_uri_priv' ] ) ;
1012
+ }
1013
+ if ( isset( $this->options[ 'optm_excludes' ] ) ) {
1014
+ update_option( LiteSpeed_Cache_Config::ITEM_OPTM_EXCLUDES, $this->options[ 'optm_excludes' ] ) ;
1015
+ }
1016
+ if ( isset( $this->options[ 'excludes_uri' ] ) ) {
1017
+ update_option( LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI, $this->options[ 'excludes_uri' ] ) ;
1018
+ }
1019
+
1020
$this->options = self::option_diff( $default_options, $this->options ) ;
1021
1022
$res = $this->update_options() ;
includes/litespeed-cache-control.class.php CHANGED
@@ -514,9 +514,9 @@ class LiteSpeed_Cache_Control
514
public static function finalize()
515
{
516
// Check if URI is forced cache
517
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_FORCE_CACHE_URI ) ;
518
if ( ! empty( $excludes ) ) {
519
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
520
if ( $result ) {
521
self::force_cacheable() ;
522
LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ) ;
@@ -635,9 +635,9 @@ class LiteSpeed_Cache_Control
635
// }
636
637
// Check private cache URI setting
638
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CACHE_URI_PRIV ) ;
639
if ( ! empty( $excludes ) ) {
640
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
641
if ( $result ) {
642
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
643
}
@@ -646,9 +646,9 @@ class LiteSpeed_Cache_Control
646
if ( ! self::is_forced_cacheable() ) {
647
648
// Check if URI is excluded from cache
649
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_EXCLUDES_URI ) ;
650
if ( ! empty( $excludes ) ) {
651
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
652
if ( $result ) {
653
return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
654
}
514
public static function finalize()
515
{
516
// Check if URI is forced cache
517
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_FORCE_CACHE_URI ) ;
518
if ( ! empty( $excludes ) ) {
519
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
520
if ( $result ) {
521
self::force_cacheable() ;
522
LiteSpeed_Cache_Log::debug( '[Ctrl] Forced cacheable due to setting: ' . $result ) ;
635
// }
636
637
// Check private cache URI setting
638
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_CACHE_URI_PRIV ) ;
639
if ( ! empty( $excludes ) ) {
640
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
641
if ( $result ) {
642
self::set_private( 'Admin cfg Private Cached URI: ' . $result ) ;
643
}
646
if ( ! self::is_forced_cacheable() ) {
647
648
// Check if URI is excluded from cache
649
+ $excludes = LiteSpeed_Cache_Config::get_instance()->get_item( LiteSpeed_Cache_Config::ITEM_EXCLUDES_URI ) ;
650
if ( ! empty( $excludes ) ) {
651
+ $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], $excludes ) ;
652
if ( $result ) {
653
return $this->_no_cache_for( 'Admin configured URI Do not cache: ' . $result ) ;
654
}
includes/litespeed-cache-gui.class.php CHANGED
@@ -171,6 +171,8 @@ class LiteSpeed_Cache_GUI
171
{
172
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.php" ;
173
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.slack.php" ;
174
}
175
176
/**
@@ -430,6 +432,15 @@ class LiteSpeed_Cache_GUI
430
) );
431
}
432
433
}
434
435
/**
171
{
172
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.php" ;
173
include_once LSCWP_DIR . "admin/tpl/inc/banner_promo.slack.php" ;
174
+
175
+ include_once LSCWP_DIR . "admin/tpl/inc/disabled_all.php" ;
176
}
177
178
/**
432
) );
433
}
434
435
+ if ( LiteSpeed_Cache_CSS::has_ccss_cache() ) {
436
+ $wp_admin_bar->add_menu( array(
437
+ 'parent' => 'litespeed-menu',
438
+ 'id' => 'litespeed-purge-ccss',
439
+ 'title' => __( 'Purge All', 'litespeed-cache' ) . ' - ' . __( 'Critical CSS', 'litespeed-cache' ),
440
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE, LiteSpeed_Cache_Purge::TYPE_PURGE_ALL_CCSS ),
441
+ 'meta' => array( 'tabindex' => '0' ),
442
+ ) );
443
+ }
444
}
445
446
/**
includes/litespeed-cache-log.class.php CHANGED
@@ -235,17 +235,23 @@ class LiteSpeed_Cache_Log
235
if ( defined( 'LSCWP_LOG_MORE' ) && $backtrace_limit !== false ) {
236
$trace = version_compare( PHP_VERSION, '5.4.0', '<' ) ? debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $backtrace_limit + 2 ) ;
237
for ( $i=1 ; $i <= $backtrace_limit + 1 ; $i++ ) {// the 0st item is push()
238
- if ( empty( $trace[$i]['class'] ) ) {
239
- break ;
240
}
241
- if ( $trace[$i]['class'] == 'LiteSpeed_Cache_Log' ) {
242
- continue ;
243
}
244
- $log = str_replace('LiteSpeed_Cache', 'LSC', $trace[$i]['class']) . $trace[$i]['type'] . $trace[$i]['function'] . '()' ;
245
if ( ! empty( $trace[$i-1]['line'] ) ) {
246
$log .= '@' . $trace[$i-1]['line'] ;
247
}
248
- $msg .= " \ $log" ;
249
}
250
251
}
235
if ( defined( 'LSCWP_LOG_MORE' ) && $backtrace_limit !== false ) {
236
$trace = version_compare( PHP_VERSION, '5.4.0', '<' ) ? debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, $backtrace_limit + 2 ) ;
237
for ( $i=1 ; $i <= $backtrace_limit + 1 ; $i++ ) {// the 0st item is push()
238
+ if ( empty( $trace[ $i ][ 'class' ] ) ) {
239
+ if ( empty( $trace[ $i ][ 'file' ] ) ) {
240
+ break ;
241
+ }
242
+ $log = "\n" . $trace[ $i ][ 'file' ] ;
243
}
244
+ else {
245
+ if ( $trace[$i]['class'] == 'LiteSpeed_Cache_Log' ) {
246
+ continue ;
247
+ }
248
+
249
+ $log = str_replace('LiteSpeed_Cache', 'LSC', $trace[$i]['class']) . $trace[$i]['type'] . $trace[$i]['function'] . '()' ;
250
}
251
if ( ! empty( $trace[$i-1]['line'] ) ) {
252
$log .= '@' . $trace[$i-1]['line'] ;
253
}
254
+ $msg .= " => $log" ;
255
}
256
257
}
includes/litespeed-cache-optimize.class.php CHANGED
@@ -16,6 +16,7 @@ class LiteSpeed_Cache_Optimize
16
17
const DIR_MIN = '/min' ;
18
const CSS_ASYNC_LIB = '/min/css_async.js' ;
19
20
private $content ;
21
private $http2_headers = array() ;
@@ -74,7 +75,7 @@ class LiteSpeed_Cache_Optimize
74
75
$this->_static_request_check() ;
76
77
- if ( ! $this->_can_optm() ) {
78
return ;
79
}
80
@@ -90,7 +91,7 @@ class LiteSpeed_Cache_Optimize
90
91
// Check if there is any critical css rules setting
92
if ( $this->cfg_css_async ) {
93
- add_action( 'wp_head', array( $this, 'prepend_critical_css' ), 1 ) ;
94
}
95
96
/**
@@ -154,24 +155,6 @@ class LiteSpeed_Cache_Optimize
154
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ) ;
155
}
156
157
- /**
158
- * Output critical css
159
- *
160
- * @since 1.3
161
- * @access public
162
- * @return string The static file content
163
- */
164
- public function prepend_critical_css()
165
- {
166
-
167
- $rules = get_option( LiteSpeed_Cache_Config::ITEM_OPTM_CSS ) ;
168
- if ( ! $rules ) {
169
- return ;
170
- }
171
-
172
- echo '<style id="litespeed-optm-css-rules">' . $rules . '</style>' ;
173
- }
174
-
175
/**
176
* Check if the request is for static file
177
*
@@ -185,9 +168,7 @@ class LiteSpeed_Cache_Optimize
185
if ( ( $this->cfg_css_async || $this->cfg_ggfonts_async ) && strpos( $_SERVER[ 'REQUEST_URI' ], self::CSS_ASYNC_LIB ) !== false ) {
186
LiteSpeed_Cache_Log::debug( '[Optm] start serving static file' ) ;
187
188
- $file = LSCWP_DIR . 'js/css_async.min.js' ;
189
-
190
- $content = Litespeed_File::read( $file ) ;
191
192
$static_file = LSCWP_CONTENT_DIR . '/cache/js/css_async.js' ;
193
@@ -318,33 +299,6 @@ class LiteSpeed_Cache_Optimize
318
return $src ;
319
}
320
321
- /**
322
- * Check if can run optimize
323
- *
324
- * @since 1.3
325
- * @access private
326
- */
327
- private function _can_optm()
328
- {
329
- if ( is_admin() ) {
330
- return false ;
331
- }
332
-
333
- if ( is_feed() ) {
334
- return false ;
335
- }
336
-
337
- if ( is_preview() ) {
338
- return false ;
339
- }
340
-
341
- if ( LiteSpeed_Cache_Router::is_ajax() ) {
342
- return false ;
343
- }
344
-
345
- return true ;
346
- }
347
-
348
/**
349
* Run optimize process
350
* NOTE: As this is after cache finalized, can NOT set any cache control anymore
@@ -365,9 +319,9 @@ class LiteSpeed_Cache_Optimize
365
}
366
367
// Check if hit URI excludes
368
- $excludes = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXCLUDES ) ;
369
if ( ! empty( $excludes ) ) {
370
- $result = LiteSpeed_Cache_Utility::str_hit_array( $_SERVER[ 'REQUEST_URI' ], explode( "\n", $excludes ) ) ;
371
if ( $result ) {
372
LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
373
return $content ;
@@ -398,7 +352,7 @@ class LiteSpeed_Cache_Optimize
398
*/
399
private function _optimize()
400
{
401
- if ( ! $this->_can_optm() ) {
402
LiteSpeed_Cache_Log::debug( '[Optm] bypass: admin/feed/preview' ) ;
403
return ;
404
}
@@ -636,9 +590,15 @@ class LiteSpeed_Cache_Optimize
636
637
// Append async compatibility lib to head
638
if ( $this->cfg_css_async || $this->cfg_ggfonts_async ) {
639
- $css_async_lib_url = LiteSpeed_Cache_Utility::get_permalink_url( self::CSS_ASYNC_LIB ) ;
640
- $this->html_head .= "<script src='" . $css_async_lib_url . "' " . ( $this->cfg_js_defer ? 'defer' : '' ) . "></script>" ;// Don't exclude it from defer for now
641
- $this->append_http2( $css_async_lib_url, 'js' ) ; // async lib will be http/2 pushed always
642
}
643
644
if ( $this->cfg_ggfonts_async ) {
@@ -1226,6 +1186,3 @@ class LiteSpeed_Cache_Optimize
1226
}
1227
1228
}
1229
-
1230
-
1231
-
16
17
const DIR_MIN = '/min' ;
18