LiteSpeed Cache - Version 2.1.2

Version Description

  • Mar 28 2018 =
  • [NEW] Image Optimization Clean Up Unfinished Data feature.
  • [IAPI] IAPI v2.1.2.
  • [IMPROVEMENT] CSS/JS Minify Reduced loading time significantly by improving CSS/JS minify loading process. (@kokers)
  • [IMPROVEMENT] CSS/JS Minify Cache empty JS Minify content. (@kokers)
  • [IMPROVEMENT] Cache Cache 301 redirect when scheme/host are same.
  • [BUGFIX] Media Lazy load now can support webp. (@relle)
  • [UPDATE] CSS/JS Optimize Serve static files for CSS async & lazy load JS library.
  • [UPDATE] Report Appended Basic/Advanced View setting to Report.
  • [UPDATE] CSS/JS Minify Removed zero-width space from CSS/JS content.
  • [GUI] Added Purge CSS/JS Cache link in Admin.
Download this release

Release Info

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

Code changes from version 2.1.1.1 to 2.1.2

admin/admin-api.class.php CHANGED
@@ -29,6 +29,7 @@ class LiteSpeed_Cache_Admin_API
29
const IAPI_ACTION_PULL_IMG = 'client_pull' ;
30
const IAPI_ACTION_PULL_IMG_FAILED = 'client_pull_failed' ;
31
const IAPI_ACTION_REQUEST_DESTROY = 'imgoptm_destroy' ;
32
const IAPI_ACTION_ENV_REPORT = 'env_report' ;
33
34
/**
29
const IAPI_ACTION_PULL_IMG = 'client_pull' ;
30
const IAPI_ACTION_PULL_IMG_FAILED = 'client_pull_failed' ;
31
const IAPI_ACTION_REQUEST_DESTROY = 'imgoptm_destroy' ;
32
+ const IAPI_ACTION_REQUEST_DESTROY_UNFINISHED = 'imgoptm_destroy_unfinished' ;
33
const IAPI_ACTION_ENV_REPORT = 'env_report' ;
34
35
/**
admin/litespeed-cache-admin-report.class.php CHANGED
@@ -171,7 +171,15 @@ class LiteSpeed_Cache_Admin_Report
171
}
172
}
173
174
- $options[ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING ] = get_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING ) ;
175
176
$report = $this->build_environment_report($_SERVER, $options, $extras, $paths) ;
177
return $report ;
171
}
172
}
173
174
+ $item_options = array(
175
+ LiteSpeed_Cache_Config::ITEM_CDN_MAPPING,
176
+ LiteSpeed_Cache_Config::ITEM_SETTING_MODE,
177
+ ) ;
178
+
179
+ foreach ( $item_options as $v ) {
180
+ $options[ $v ] = get_option( $v ) ;
181
+ }
182
+
183
184
$report = $this->build_environment_report($_SERVER, $options, $extras, $paths) ;
185
return $report ;
admin/litespeed-cache-admin-rules.class.php CHANGED
@@ -24,14 +24,11 @@ class LiteSpeed_Cache_Admin_Rules
24
private $theme_htaccess_readable = false ;
25
private $theme_htaccess_writable = false ;
26
27
- const RW_LOOKUP_BOTH = "CacheLookup on" ;
28
- const RW_PRIV_BYPASS_POST_PURGE = "RewriteRule .* - [E=Cache-Control:no-autoflush]" ;
29
- const RW_OPTM_NO_VARY = "RewriteRule min/\w+\.(css|js) - [E=cache-control:no-vary]" ;
30
-
31
const LS_MODULE_START = '<IfModule LiteSpeed>' ;
32
const EXPIRES_MODULE_START = '<IfModule mod_expires.c>' ;
33
const LS_MODULE_END = '</IfModule>' ;
34
const LS_MODULE_REWRITE_START = '<IfModule mod_rewrite.c>' ;
35
private static $LS_MODULE_REWRITE_ON ;
36
const LS_MODULE_DONOTEDIT = "## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##" ;
37
const MARKER = 'LSCACHE' ;
@@ -73,10 +70,10 @@ class LiteSpeed_Cache_Admin_Rules
73
}
74
75
self::$LS_MODULE_REWRITE_ON = array(
76
- 'RewriteEngine on',
77
- self::RW_LOOKUP_BOTH,
78
- self::RW_PRIV_BYPASS_POST_PURGE,
79
- self::RW_OPTM_NO_VARY,
80
) ;
81
82
// backend .htaccess privilege
@@ -526,6 +523,26 @@ class LiteSpeed_Cache_Admin_Rules
526
return $rules ;
527
}
528
529
/**
530
* Generate CORS rules for fonts
531
*
@@ -677,6 +694,12 @@ class LiteSpeed_Cache_Admin_Rules
677
$new_rules_nonls[] = '' ;
678
}
679
680
681
// Add module wrapper for LiteSpeed rules
682
if ( $new_rules || $disable_lscache_detail_rules ) {
24
private $theme_htaccess_readable = false ;
25
private $theme_htaccess_writable = false ;
26
27
const LS_MODULE_START = '<IfModule LiteSpeed>' ;
28
const EXPIRES_MODULE_START = '<IfModule mod_expires.c>' ;
29
const LS_MODULE_END = '</IfModule>' ;
30
const LS_MODULE_REWRITE_START = '<IfModule mod_rewrite.c>' ;
31
+ const REWRITE_ON = 'RewriteEngine on' ;
32
private static $LS_MODULE_REWRITE_ON ;
33
const LS_MODULE_DONOTEDIT = "## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##" ;
34
const MARKER = 'LSCACHE' ;
70
}
71
72
self::$LS_MODULE_REWRITE_ON = array(
73
+ self::REWRITE_ON,
74
+ "CacheLookup on",
75
+ "RewriteRule .* - [E=Cache-Control:no-autoflush]",
76
+ "RewriteRule ^min/\w+\.(css|js) - [E=cache-control:no-vary]",
77
) ;
78
79
// backend .htaccess privilege
523
return $rules ;
524
}
525
526
+ /**
527
+ * Generate minify rules
528
+ *
529
+ * @since 2.1.2
530
+ * @access private
531
+ * @return array Rules set
532
+ */
533
+ private function _minify_rules()
534
+ {
535
+ $rules = array(
536
+ self::LS_MODULE_REWRITE_START,
537
+ self::REWRITE_ON,
538
+ 'RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} ^(.*)/min/(\w+)\.(css|js)#x27;,
539
+ 'RewriteCond %1/' . basename( LSCWP_CONTENT_DIR ) . '/cache/$2/$1.$2 -f',
540
+ 'RewriteRule min/(\w+)\.(css|js) ' . basename( LSCWP_CONTENT_DIR ) . '/cache/$2/$1.$2 [L]',
541
+ self::LS_MODULE_END,
542
+ ) ;
543
+ return $rules ;
544
+ }
545
+
546
/**
547
* Generate CORS rules for fonts
548
*
694
$new_rules_nonls[] = '' ;
695
}
696
697
+ // CSS/JS static file rewrite
698
+ $new_rules_nonls[] = $new_rules_backend_nonls[] = self::MARKER_MINIFY . self::MARKER_START ;
699
+ $new_rules_nonls = array_merge( $new_rules_nonls, $this->_minify_rules() ) ;
700
+ $new_rules_backend_nonls = array_merge( $new_rules_backend_nonls, $this->_minify_rules() ) ;
701
+ $new_rules_nonls[] = $new_rules_backend_nonls[] = self::MARKER_MINIFY . self::MARKER_END ;
702
+ $new_rules_nonls[] = '' ;
703
704
// Add module wrapper for LiteSpeed rules
705
if ( $new_rules || $disable_lscache_detail_rules ) {
admin/tpl/edit_htaccess.php CHANGED
@@ -3,6 +3,7 @@ if (!defined('WPINC')) die;
3
4
$readonly = LiteSpeed_Cache_Admin_Rules::writable() ? '' : 'readonly';
5
$content = LiteSpeed_Cache_Admin_Rules::get_instance()->htaccess_read();
6
7
// Check if there is `ExpiresDefault` in .htaccess
8
if ( defined( 'LITESPEED_ON' ) ) {
@@ -58,9 +59,9 @@ if ( defined( 'LITESPEED_ON' ) ) {
58
59
<div class="litespeed-title"><?php echo sprintf(__('Current %s Contents', 'litespeed-cache'), '.htaccess'); ?></div>
60
61
- <!--p><span class="attention"><?php echo sprintf(__('DO NOT EDIT ANYTHING WITHIN %s', 'litespeed-cache'), LiteSpeed_Cache_Admin_Rules::LS_MODULE_DONOTEDIT); ?></span></p-->
62
63
- <p><?php echo __('These are added by the LS Cache plugin and may cause problems if they are changed.', 'litespeed-cache'); ?></p>
64
65
<textarea name="<?php echo LiteSpeed_Cache_Admin_Rules::EDITOR_TEXTAREA_NAME; ?>" wrap="off" rows="50" class="litespeed-input-long"
66
<?php echo $readonly; ?>
3
4
$readonly = LiteSpeed_Cache_Admin_Rules::writable() ? '' : 'readonly';
5
$content = LiteSpeed_Cache_Admin_Rules::get_instance()->htaccess_read();
6
+ $htaccess_path = LiteSpeed_Cache_Admin_Rules::get_frontend_htaccess() ;
7
8
// Check if there is `ExpiresDefault` in .htaccess
9
if ( defined( 'LITESPEED_ON' ) ) {
59
60
<div class="litespeed-title"><?php echo sprintf(__('Current %s Contents', 'litespeed-cache'), '.htaccess'); ?></div>
61
62
+ <p><span class="attention"><?php echo sprintf(__('DO NOT EDIT ANYTHING WITHIN %s', 'litespeed-cache'), '<code>' . LiteSpeed_Cache_Admin_Rules::LS_MODULE_DONOTEDIT . '</code>' ); ?></span></p>
63
64
+ <h4><?php echo $htaccess_path ; ?></h4>
65
66
<textarea name="<?php echo LiteSpeed_Cache_Admin_Rules::EDITOR_TEXTAREA_NAME; ?>" wrap="off" rows="50" class="litespeed-input-long"
67
<?php echo $readonly; ?>
admin/tpl/image_optimization.php CHANGED
@@ -163,8 +163,8 @@ LiteSpeed_Cache_GUI::show_promo() ;
163
164
<p>
165
<?php echo __('Images requested', 'litespeed-cache') ; ?>:
166
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_requested_groups' ] ) ; ?></b>
167
- (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_requested' ], 'image' ) ; ?></b>)
168
</p>
169
<p class="litespeed-desc">
170
<?php echo __( 'After LiteSpeed\'s Image Optimization Server finishes optimization, it will notify your site to pull the optimized images.', 'litespeed-cache' ) ; ?>
@@ -172,10 +172,10 @@ LiteSpeed_Cache_GUI::show_promo() ;
172
</p>
173
<p>
174
<?php echo __('Images notified to pull', 'litespeed-cache') ; ?>:
175
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_server_finished_groups' ] ) ; ?></b>
176
- (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_server_finished' ], 'image' ) ; ?></b>)
177
178
- <?php if ( $img_count[ 'total_server_finished' ] && ! $is_running ) : ?>
179
<a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IMG_OPTM, LiteSpeed_Cache_Img_Optm::TYPE_IMG_PULL ) ; ?>" class="litespeed-btn-success">
180
<?php echo __( 'Pull Images', 'litespeed-cache' ) ; ?>
181
</a>
@@ -191,23 +191,37 @@ LiteSpeed_Cache_GUI::show_promo() ;
191
</p>
192
<p>
193
<?php echo __('Images optimized and pulled', 'litespeed-cache') ; ?>:
194
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_pulled_groups' ] ) ; ?></b>
195
- (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_pulled' ], 'image' ) ; ?></b>)
196
- </p>
197
- <p>
198
- <?php echo __('Images failed to optimize', 'litespeed-cache') ; ?>:
199
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_err_groups' ] ) ; ?></b>
200
- (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_err' ], 'image' ) ; ?></b>)
201
- </p>
202
- <p>
203
- <?php echo __('Image files missing', 'litespeed-cache') ; ?>:
204
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_miss_groups' ] ) ; ?></b>
205
- (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_miss' ], 'image' ) ; ?></b>)
206
- </p>
207
- <p>
208
- <?php echo __('Images with wrong meta', 'litespeed-cache') ; ?>:
209
- <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'total_xmeta_groups' ] ) ; ?></b>
210
</p>
211
<p><a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:image-optimization#image_optimization_in_litespeed_cache_for_wordpress" target="_blank"><?php echo __('Learn More', 'litespeed-cache') ; ?></a></p>
212
213
<hr />
@@ -258,17 +272,25 @@ LiteSpeed_Cache_GUI::show_promo() ;
258
</span>
259
260
<br />
261
- <a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IMG_OPTM, LiteSpeed_Cache_Img_Optm::TYPE_IMG_OPTIMIZE_DESTROY ) ; ?>" class="litespeed-btn-danger">
262
<?php echo __( 'Destroy All Optimization Data!', 'litespeed-cache' ) ; ?>
263
</a>
264
<span class="litespeed-desc">
265
<?php echo __( 'Remove all previous image optimization requests/results, revert completed optimizations, and delete all optimization files.', 'litespeed-cache' ) ; ?>
266
<font class="litespeed-warning">
267
<?php echo __('NOTE', 'litespeed-cache'); ?>:
268
- <?php echo sprintf( __( 'If there are unfinished requests in progress, the requests\' credits will NOT be recovered.', 'litespeed-cache' ), 'jQuery', __( 'JS Combine', 'litespeed-cache' ) ) ; ?>
269
</font>
270
-
271
</span>
272
<?php endif ; ?>
273
274
163
164
<p>
165
<?php echo __('Images requested', 'litespeed-cache') ; ?>:
166
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_REQUESTED ] ) ; ?></b>
167
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_REQUESTED ], 'image' ) ; ?></b>)
168
</p>
169
<p class="litespeed-desc">
170
<?php echo __( 'After LiteSpeed\'s Image Optimization Server finishes optimization, it will notify your site to pull the optimized images.', 'litespeed-cache' ) ; ?>
172
</p>
173
<p>
174
<?php echo __('Images notified to pull', 'litespeed-cache') ; ?>:
175
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_NOTIFIED ] ) ; ?></b>
176
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_NOTIFIED ], 'image' ) ; ?></b>)
177
178
+ <?php if ( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_NOTIFIED ] && ! $is_running ) : ?>
179
<a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IMG_OPTM, LiteSpeed_Cache_Img_Optm::TYPE_IMG_PULL ) ; ?>" class="litespeed-btn-success">
180
<?php echo __( 'Pull Images', 'litespeed-cache' ) ; ?>
181
</a>
191
</p>
192
<p>
193
<?php echo __('Images optimized and pulled', 'litespeed-cache') ; ?>:
194
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_PULLED ] ) ; ?></b>
195
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_PULLED ], 'image' ) ; ?></b>)
196
</p>
197
+
198
+ <div class="litespeed-desc litespeed-left20">
199
+ <p>
200
+ <?php echo __('Images failed to fetch', 'litespeed-cache') ; ?>:
201
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR_FETCH ] ) ; ?></b>
202
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR_FETCH ], 'image' ) ; ?></b>)
203
+ </p>
204
+ <p>
205
+ <?php echo __('Images failed to optimize', 'litespeed-cache') ; ?>:
206
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR_OPTM ] ) ; ?></b>
207
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR_OPTM ], 'image' ) ; ?></b>)
208
+ </p>
209
+ <p>
210
+ <?php echo __('Images failed with other errors', 'litespeed-cache') ; ?>:
211
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR ] ) ; ?></b>
212
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_ERR ], 'image' ) ; ?></b>)
213
+ </p>
214
+ <p>
215
+ <?php echo __('Image files missing', 'litespeed-cache') ; ?>:
216
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'group.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_MISS ] ) ; ?></b>
217
+ (<b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_MISS ], 'image' ) ; ?></b>)
218
+ </p>
219
+ <p>
220
+ <?php echo __('Images with wrong meta', 'litespeed-cache') ; ?>:
221
+ <b><?php echo LiteSpeed_Cache_Admin_Display::print_plural( $img_count[ 'img.' . LiteSpeed_Cache_Img_Optm::DB_IMG_OPTIMIZE_STATUS_XMETA ] ) ; ?></b>
222
+ </p>
223
+ </div>
224
+
225
<p><a href="https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:image-optimization#image_optimization_in_litespeed_cache_for_wordpress" target="_blank"><?php echo __('Learn More', 'litespeed-cache') ; ?></a></p>
226
227
<hr />
272
</span>
273
274
<br />
275
+ <a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IMG_OPTM, LiteSpeed_Cache_Img_Optm::TYPE_IMG_OPTM_DESTROY_UNFINISHED ) ; ?>" class="litespeed-btn-warning">
276
+ <?php echo __( 'Clean Up Unfinished Data', 'litespeed-cache' ) ; ?>
277
+ </a>
278
+ <span class="litespeed-desc">
279
+ <?php echo __( 'Remove all previous unfinished image optimization requests.', 'litespeed-cache' ) ; ?>
280
+ </span>
281
+
282
+ <br />
283
+ <a href="<?php echo LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_IMG_OPTM, LiteSpeed_Cache_Img_Optm::TYPE_IMG_OPTM_DESTROY ) ; ?>" class="litespeed-btn-danger">
284
<?php echo __( 'Destroy All Optimization Data!', 'litespeed-cache' ) ; ?>
285
</a>
286
<span class="litespeed-desc">
287
<?php echo __( 'Remove all previous image optimization requests/results, revert completed optimizations, and delete all optimization files.', 'litespeed-cache' ) ; ?>
288
<font class="litespeed-warning">
289
<?php echo __('NOTE', 'litespeed-cache'); ?>:
290
+ <?php echo __( 'This will also reset the credit level.', 'litespeed-cache' ) ; ?>
291
</font>
292
</span>
293
+
294
<?php endif ; ?>
295
296
admin/tpl/manage/manage_purge.php CHANGED
@@ -48,11 +48,6 @@ $_panels = array(
48
'tag' => LiteSpeed_Cache::ACTION_PURGE_ALL,
49
'icon' => 'purge-all',
50
'title_cls' => 'litespeed-warning',
51
- 'cfm' => is_multisite() && is_network_admin() ?
52
- esc_html( __( 'This will purge everything for all blogs.', 'litespeed-cache' ) ) . ' ' .
53
- esc_html( __( 'Are you sure you want to purge all?', 'litespeed-cache' ) )
54
- :
55
- esc_html( __( 'Are you sure you want to purge all?', 'litespeed-cache' ) )
56
),
57
) ;
58
48
'tag' => LiteSpeed_Cache::ACTION_PURGE_ALL,
49
'icon' => 'purge-all',
50
'title_cls' => 'litespeed-warning',
51
),
52
) ;
53
inc/config.class.php CHANGED
@@ -379,7 +379,7 @@ class LiteSpeed_Cache_Config
379
return $this->options[$id] ;
380
}
381
382
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Invalid option ID ' . $id ) ;
383
384
return NULL ;
385
}
@@ -469,7 +469,7 @@ class LiteSpeed_Cache_Config
469
}
470
471
if ( $group ) {
472
- LiteSpeed_Cache_Log::debug2( 'Config: role in vary_group [group] ' . $group ) ;
473
}
474
475
return $group ;
@@ -919,7 +919,7 @@ class LiteSpeed_Cache_Config
919
self::ITEM_CDN_MAPPING_FILETYPE => $this->options[ 'cdn_filetype' ],
920
) ;
921
update_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array( $cdn_mapping ) ) ;
922
- LiteSpeed_Cache_Log::debug( "Config: plugin_upgrade option adding CDN map" ) ;
923
}
924
925
$this->options = self::option_diff( $default_options, $this->options ) ;
@@ -927,7 +927,7 @@ class LiteSpeed_Cache_Config
927
$res = $this->update_options() ;
928
define( 'LSWCP_EMPTYCACHE', true ) ;// clear all sites caches
929
LiteSpeed_Cache_Purge::purge_all() ;
930
- LiteSpeed_Cache_Log::debug( "Config: plugin_upgrade option changed = $res" ) ;
931
932
// Update img_optm table data for upgrading
933
LiteSpeed_Cache_Data::get_instance() ;
@@ -952,7 +952,7 @@ class LiteSpeed_Cache_Config
952
953
$res = update_site_option( self::OPTION_NAME, $options ) ;
954
955
- LiteSpeed_Cache_Log::debug( "plugin_upgrade option changed = $res\n" ) ;
956
}
957
958
/**
@@ -1026,7 +1026,7 @@ class LiteSpeed_Cache_Config
1026
1027
$res = add_option( self::OPTION_NAME, $this->get_default_options() ) ;
1028
1029
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[Config] plugin_activation update option = " . var_export( $res, true ) ) ;
1030
1031
$disable_lscache = false ;
1032
379
return $this->options[$id] ;
380
}
381
382
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Cfg] Invalid option ID ' . $id ) ;
383
384
return NULL ;
385
}
469
}
470
471
if ( $group ) {
472
+ LiteSpeed_Cache_Log::debug2( '[Cfg] role in vary_group [group] ' . $group ) ;
473
}
474
475
return $group ;
919
self::ITEM_CDN_MAPPING_FILETYPE => $this->options[ 'cdn_filetype' ],
920
) ;
921
update_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array( $cdn_mapping ) ) ;
922
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
923
}
924
925
$this->options = self::option_diff( $default_options, $this->options ) ;
927
$res = $this->update_options() ;
928
define( 'LSWCP_EMPTYCACHE', true ) ;// clear all sites caches
929
LiteSpeed_Cache_Purge::purge_all() ;
930
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option changed = $res" ) ;
931
932
// Update img_optm table data for upgrading
933
LiteSpeed_Cache_Data::get_instance() ;
952
953
$res = update_site_option( self::OPTION_NAME, $options ) ;
954
955
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option changed = $res\n" ) ;
956
}
957
958
/**
1026
1027
$res = add_option( self::OPTION_NAME, $this->get_default_options() ) ;
1028
1029
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[Cfg] plugin_activation update option = " . var_export( $res, true ) ) ;
1030
1031
$disable_lscache = false ;
1032
inc/control.class.php CHANGED
@@ -101,7 +101,7 @@ class LiteSpeed_Cache_Control
101
return ;
102
}
103
self::$_control |= self::BM_NO_VARY ;
104
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> no-vary', 3 ) ;
105
}
106
107
/**
@@ -127,7 +127,7 @@ class LiteSpeed_Cache_Control
127
return ;
128
}
129
self::$_control |= self::BM_STALE ;
130
- LiteSpeed_Cache_Log::debug('X Cache_control -> stale') ;
131
}
132
133
/**
@@ -158,7 +158,7 @@ class LiteSpeed_Cache_Control
158
if ( $reason ) {
159
$reason = "( $reason )" ;
160
}
161
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> shared ' . $reason ) ;
162
}
163
164
/**
@@ -188,7 +188,7 @@ class LiteSpeed_Cache_Control
188
if ( $reason ) {
189
$reason = "( $reason )" ;
190
}
191
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> public forced ' . $reason ) ;
192
}
193
194
/**
@@ -218,7 +218,7 @@ class LiteSpeed_Cache_Control
218
if ( $reason ) {
219
$reason = "( $reason )" ;
220
}
221
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> private ' . $reason ) ;
222
}
223
224
/**
@@ -241,7 +241,7 @@ class LiteSpeed_Cache_Control
241
public static function set_cacheable()
242
{
243
self::$_control |= self::BM_CACHEABLE ;
244
- LiteSpeed_Cache_Log::debug( 'X Cache_control init on' ) ;
245
}
246
247
/**
@@ -257,7 +257,7 @@ class LiteSpeed_Cache_Control
257
if ( $reason ) {
258
$reason = "( $reason )" ;
259
}
260
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> no Cache ' . $reason, 2 ) ;
261
}
262
263
/**
@@ -298,7 +298,7 @@ class LiteSpeed_Cache_Control
298
{
299
if ( is_numeric($ttl) ) {
300
self::$_custom_ttl = $ttl ;
301
- LiteSpeed_Cache_Log::debug('X Cache_control TTL -> ' . $ttl) ;
302
}
303
}
304
@@ -328,7 +328,7 @@ class LiteSpeed_Cache_Control
328
if ( $ttl < 0 ) {
329
$ttl += 86400 ;// add one day
330
}
331
- LiteSpeed_Cache_Log::debug( 'X Cache_control TTL is limited to ' . $ttl ) ;
332
return $ttl ;
333
}
334
}
@@ -374,12 +374,30 @@ class LiteSpeed_Cache_Control
374
public static function check_redirect( $location, $status )
375
{
376
if ( ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ) { // dont check $status == '301' anymore
377
- LiteSpeed_Cache_Log::debug( "301 from " . $_SERVER[ 'SCRIPT_URI' ] ) ;
378
- LiteSpeed_Cache_Log::debug( "301 to $location" ) ;
379
- if ( parse_url( $_SERVER[ 'SCRIPT_URI' ], PHP_URL_PATH ) == parse_url( $location, PHP_URL_PATH ) ) {
380
self::set_nocache( '301 to same url' ) ;
381
}
382
}
383
return $location ;
384
}
385
@@ -433,7 +451,7 @@ class LiteSpeed_Cache_Control
433
// if is not cacheable, terminate check
434
// Even no need to run 3rd party hook
435
if ( ! self::is_cacheable() ) {
436
- LiteSpeed_Cache_Log::debug( 'not cacheable before ctrl finalize' ) ;
437
return ;
438
}
439
@@ -458,7 +476,7 @@ class LiteSpeed_Cache_Control
458
459
// if is not cacheable, terminate check
460
if ( ! self::is_cacheable() ) {
461
- LiteSpeed_Cache_Log::debug( 'not cacheable after api_control' ) ;
462
return ;
463
}
464
@@ -617,7 +635,7 @@ class LiteSpeed_Cache_Control
617
*/
618
private function _no_cache_for( $reason )
619
{
620
- LiteSpeed_Cache_Log::debug('X Cache_control off - ' . $reason) ;
621
return false ;
622
}
623
101
return ;
102
}
103
self::$_control |= self::BM_NO_VARY ;
104
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> no-vary', 3 ) ;
105
}
106
107
/**
127
return ;
128
}
129
self::$_control |= self::BM_STALE ;
130
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control -> stale') ;
131
}
132
133
/**
158
if ( $reason ) {
159
$reason = "( $reason )" ;
160
}
161
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> shared ' . $reason ) ;
162
}
163
164
/**
188
if ( $reason ) {
189
$reason = "( $reason )" ;
190
}
191
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> public forced ' . $reason ) ;
192
}
193
194
/**
218
if ( $reason ) {
219
$reason = "( $reason )" ;
220
}
221
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> private ' . $reason ) ;
222
}
223
224
/**
241
public static function set_cacheable()
242
{
243
self::$_control |= self::BM_CACHEABLE ;
244
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control init on' ) ;
245
}
246
247
/**
257
if ( $reason ) {
258
$reason = "( $reason )" ;
259
}
260
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> no Cache ' . $reason, 2 ) ;
261
}
262
263
/**
298
{
299
if ( is_numeric($ttl) ) {
300
self::$_custom_ttl = $ttl ;
301
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control TTL -> ' . $ttl) ;
302
}
303
}
304
328
if ( $ttl < 0 ) {
329
$ttl += 86400 ;// add one day
330
}
331
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control TTL is limited to ' . $ttl ) ;
332
return $ttl ;
333
}
334
}
374
public static function check_redirect( $location, $status )
375
{
376
if ( ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ) { // dont check $status == '301' anymore
377
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 from " . $_SERVER[ 'SCRIPT_URI' ] ) ;
378
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 to $location" ) ;
379
+
380
+ $to_check = array(
381
+ PHP_URL_SCHEME,
382
+ PHP_URL_HOST,
383
+ PHP_URL_PATH,
384
+ ) ;
385
+
386
+ $is_same_redirect = true ;
387
+
388
+ foreach ( $to_check as $v ) {
389
+ if ( parse_url( $_SERVER[ 'SCRIPT_URI' ], $v ) != parse_url( $location, $v ) ) {
390
+ $is_same_redirect = false ;
391
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 different redirection" ) ;
392
+ break ;
393
+ }
394
+ }
395
+
396
+ if ( $is_same_redirect ) {
397
self::set_nocache( '301 to same url' ) ;
398
}
399
}
400
+
401
return $location ;
402
}
403
451
// if is not cacheable, terminate check
452
// Even no need to run 3rd party hook
453
if ( ! self::is_cacheable() ) {
454
+ LiteSpeed_Cache_Log::debug( '[Ctrl] not cacheable before ctrl finalize' ) ;
455
return ;
456
}
457
476
477
// if is not cacheable, terminate check
478
if ( ! self::is_cacheable() ) {
479
+ LiteSpeed_Cache_Log::debug( '[Ctrl] not cacheable after api_control' ) ;
480
return ;
481
}
482
635
*/
636
private function _no_cache_for( $reason )
637
{
638
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control off - ' . $reason) ;
639
return false ;
640
}
641
inc/gui.class.php CHANGED
@@ -372,11 +372,19 @@ class LiteSpeed_Cache_GUI
372
$wp_admin_bar->add_menu( array(
373
'parent' => 'litespeed-menu',
374
'id' => 'litespeed-purge-all',
375
- 'title' => __( 'LiteSpeed Cache Purge All', 'litespeed-cache' ),
376
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
377
'meta' => array( 'tabindex' => '0' ),
378
) );
379
380
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE ) ) {
381
$wp_admin_bar->add_menu( array(
382
'parent' => 'litespeed-menu',
372
$wp_admin_bar->add_menu( array(
373
'parent' => 'litespeed-menu',
374
'id' => 'litespeed-purge-all',
375
+ 'title' => __( 'LSCache Purge All', 'litespeed-cache' ),
376
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
377
'meta' => array( 'tabindex' => '0' ),
378
) );
379
380
+ $wp_admin_bar->add_menu( array(
381
+ 'parent' => 'litespeed-menu',
382
+ 'id' => 'litespeed-purge-cssjs',
383
+ 'title' => __( 'Purge CSS/JS Cache', 'litespeed-cache' ),
384
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_CSSJS ),
385
+ 'meta' => array( 'tabindex' => '0' ),
386
+ ) );
387
+
388
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE ) ) {
389
$wp_admin_bar->add_menu( array(
390
'parent' => 'litespeed-menu',
inc/img_optm.class.php CHANGED
@@ -16,7 +16,8 @@ class LiteSpeed_Cache_Img_Optm
16
const TYPE_SYNC_DATA = 'sync_data' ;
17
const TYPE_IMG_OPTIMIZE = 'img_optm' ;
18
const TYPE_IMG_OPTIMIZE_RESCAN = 'img_optm_rescan' ;
19
- const TYPE_IMG_OPTIMIZE_DESTROY = 'img_optm_destroy' ;
20
const TYPE_IMG_PULL = 'img_pull' ;
21
const TYPE_IMG_BATCH_SWITCH_ORI = 'img_optm_batch_switch_ori' ;
22
const TYPE_IMG_BATCH_SWITCH_OPTM = 'img_optm_batch_switch_optm' ;
@@ -32,6 +33,8 @@ class LiteSpeed_Cache_Img_Optm
32
const DB_IMG_OPTIMIZE_STATUS_FAILED = 'failed' ;
33
const DB_IMG_OPTIMIZE_STATUS_MISS = 'miss' ;
34
const DB_IMG_OPTIMIZE_STATUS_ERR = 'err' ;
35
const DB_IMG_OPTIMIZE_STATUS_XMETA = 'xmeta' ;
36
const DB_IMG_OPTIMIZE_SIZE = 'litespeed-optimize-size' ;
37
@@ -705,7 +708,13 @@ class LiteSpeed_Cache_Img_Optm
705
exit( json_encode( 'no/wrong server' ) ) ;
706
}
707
708
- $_allowed_status = array( self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED, self::DB_IMG_OPTIMIZE_STATUS_ERR, self::DB_IMG_OPTIMIZE_STATUS_REQUESTED ) ;
709
710
if ( empty( $_POST[ 'status' ] ) || ! in_array( $_POST[ 'status' ], $_allowed_status ) ) {
711
LiteSpeed_Cache_Log::debug( '[Img_Optm] notify exit: no/wrong status' ) ;
@@ -1069,6 +1078,53 @@ class LiteSpeed_Cache_Img_Optm
1069
return $meta_value ;
1070
}
1071
1072
/**
1073
* Send destroy all requests cmd to LiteSpeed IAPI server and get the link to finish it ( avoid click by mistake )
1074
*
@@ -1352,33 +1408,37 @@ class LiteSpeed_Cache_Img_Optm
1352
// images count from img_optm table
1353
$q_groups = "SELECT count(distinct post_id) FROM $this->_table_img_optm WHERE optm_status = %s" ;
1354
$q = "SELECT count(*) FROM $this->_table_img_optm WHERE optm_status = %s" ;
1355
- $total_requested_groups = $wpdb->get_var( $wpdb->prepare( $q_groups, self::DB_IMG_OPTIMIZE_STATUS_REQUESTED ) ) ;
1356
- $total_requested = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_REQUESTED ) ) ;
1357
- $total_server_finished_groups = $wpdb->get_var( $wpdb->prepare( $q_groups, self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED ) ) ;
1358
- $total_server_finished = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED ) ) ;
1359
- $total_pulled_groups = $wpdb->get_var( $wpdb->prepare( $q_groups, self::DB_IMG_OPTIMIZE_STATUS_PULLED ) ) ;
1360
- $total_pulled = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_PULLED ) ) ;
1361
- $total_err_groups = $wpdb->get_var( $wpdb->prepare( $q_groups, self::DB_IMG_OPTIMIZE_STATUS_ERR ) ) ;
1362
- $total_err = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_ERR ) ) ;
1363
- $total_miss_groups = $wpdb->get_var( $wpdb->prepare( $q_groups, self::DB_IMG_OPTIMIZE_STATUS_MISS ) ) ;
1364
- $total_miss = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_MISS ) ) ;
1365
- $total_xmeta_groups = $wpdb->get_var( $wpdb->prepare( $q, self::DB_IMG_OPTIMIZE_STATUS_XMETA ) ) ;
1366
-
1367
- return array(
1368
'total_img' => $total_img,
1369
'total_not_requested' => $total_not_requested,
1370
- 'total_requested_groups' => $total_requested_groups,
1371
- 'total_requested' => $total_requested,
1372
- 'total_err_groups' => $total_err_groups,
1373
- 'total_err' => $total_err,
1374
- 'total_miss_groups' => $total_miss_groups,
1375
- 'total_miss' => $total_miss,
1376
- 'total_server_finished_groups' => $total_server_finished_groups,
1377
- 'total_server_finished' => $total_server_finished,
1378
- 'total_pulled_groups' => $total_pulled_groups,
1379
- 'total_pulled' => $total_pulled,
1380
- 'total_xmeta_groups' => $total_xmeta_groups,
1381
) ;
1382
}
1383
1384
/**
@@ -1564,10 +1624,14 @@ class LiteSpeed_Cache_Img_Optm
1564
$instance->_img_optimize_rescan() ;
1565
break ;
1566
1567
- case self::TYPE_IMG_OPTIMIZE_DESTROY :
1568
$instance->_img_optimize_destroy() ;
1569
break ;
1570
1571
case self::TYPE_IMG_PULL :
1572
LiteSpeed_Cache_Log::debug( 'ImgOptm: Manually running Cron pull_optimized_img' ) ;
1573
$result = $instance->_pull_optimized_img( true ) ;
16
const TYPE_SYNC_DATA = 'sync_data' ;
17
const TYPE_IMG_OPTIMIZE = 'img_optm' ;
18
const TYPE_IMG_OPTIMIZE_RESCAN = 'img_optm_rescan' ;
19
+ const TYPE_IMG_OPTM_DESTROY = 'img_optm_destroy' ;
20
+ const TYPE_IMG_OPTM_DESTROY_UNFINISHED = 'img_optm_destroy-unfinished' ;
21
const TYPE_IMG_PULL = 'img_pull' ;
22
const TYPE_IMG_BATCH_SWITCH_ORI = 'img_optm_batch_switch_ori' ;
23
const TYPE_IMG_BATCH_SWITCH_OPTM = 'img_optm_batch_switch_optm' ;
33
const DB_IMG_OPTIMIZE_STATUS_FAILED = 'failed' ;
34
const DB_IMG_OPTIMIZE_STATUS_MISS = 'miss' ;
35
const DB_IMG_OPTIMIZE_STATUS_ERR = 'err' ;
36
+ const DB_IMG_OPTIMIZE_STATUS_ERR_FETCH = 'err_fetch' ;
37
+ const DB_IMG_OPTIMIZE_STATUS_ERR_OPTM = 'err_optm' ;
38
const DB_IMG_OPTIMIZE_STATUS_XMETA = 'xmeta' ;
39
const DB_IMG_OPTIMIZE_SIZE = 'litespeed-optimize-size' ;
40
708
exit( json_encode( 'no/wrong server' ) ) ;
709
}
710
711
+ $_allowed_status = array(
712
+ self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED,
713
+ self::DB_IMG_OPTIMIZE_STATUS_ERR,
714
+ self::DB_IMG_OPTIMIZE_STATUS_ERR_FETCH,
715
+ self::DB_IMG_OPTIMIZE_STATUS_ERR_OPTM,
716
+ self::DB_IMG_OPTIMIZE_STATUS_REQUESTED,
717
+ ) ;
718
719
if ( empty( $_POST[ 'status' ] ) || ! in_array( $_POST[ 'status' ], $_allowed_status ) ) {
720
LiteSpeed_Cache_Log::debug( '[Img_Optm] notify exit: no/wrong status' ) ;
1078
return $meta_value ;
1079
}
1080
1081
+ /**
1082
+ * Destroy all unfinished queue locally and to LiteSpeed IAPI server
1083
+ *
1084
+ * @since 2.1.2
1085
+ * @access private
1086
+ */
1087
+ private function _img_optimize_destroy_unfinished()
1088
+ {
1089
+ global $wpdb ;
1090
+
1091
+ LiteSpeed_Cache_Log::debug( '[Img_Optm] sending DESTROY_UNFINISHED cmd to LiteSpeed IAPI' ) ;
1092
+
1093
+ // Push to LiteSpeed IAPI server and recover credit
1094
+ $json = LiteSpeed_Cache_Admin_API::post( LiteSpeed_Cache_Admin_API::IAPI_ACTION_REQUEST_DESTROY_UNFINISHED ) ;
1095
+
1096
+ // confirm link will be displayed by Admin_API automatically
1097
+ if ( is_array( $json ) && $json ) {
1098
+ LiteSpeed_Cache_Log::debug( '[Img_Optm] cmd result', $json ) ;
1099
+ }
1100
+
1101
+ // If failed to run request to IAPI
1102
+ if ( ! is_array( $json ) || empty( $json[ 'success' ] ) ) {
1103
+
1104
+ // For other errors that Admin_API didn't take
1105
+ if ( ! is_array( $json ) && $json !== null ) {
1106
+ LiteSpeed_Cache_Admin_Display::error( $json ) ;
1107
+
1108
+ LiteSpeed_Cache_Log::debug( '[Img_Optm] err ', $json ) ;
1109
+ }
1110
+ return ;
1111
+ }
1112
+
1113
+ // Clear local queue
1114
+ $_status_to_clear = array(
1115
+ self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED,
1116
+ self::DB_IMG_OPTIMIZE_STATUS_REQUESTED,
1117
+ self::DB_IMG_OPTIMIZE_STATUS_ERR_FETCH,
1118
+ ) ;
1119
+ $q = "DELETE FROM $this->_table_img_optm WHERE optm_status IN ( " . implode( ',', array_fill( 0, count( $_status_to_clear ), '%s' ) ) . " )" ;
1120
+ $wpdb->query( $wpdb->prepare( $q, $_status_to_clear ) ) ;
1121
+
1122
+
1123
+ $msg = __( 'Destroy unfinished data successfully.', 'litespeed-cache' ) ;
1124
+ LiteSpeed_Cache_Admin_Display::succeed( $msg ) ;
1125
+
1126
+ }
1127
+
1128
/**
1129
* Send destroy all requests cmd to LiteSpeed IAPI server and get the link to finish it ( avoid click by mistake )
1130
*
1408
// images count from img_optm table
1409
$q_groups = "SELECT count(distinct post_id) FROM $this->_table_img_optm WHERE optm_status = %s" ;
1410
$q = "SELECT count(*) FROM $this->_table_img_optm WHERE optm_status = %s" ;
1411
+
1412
+ // The groups to check
1413
+ $images_to_check = $groups_to_check = array(
1414
+ self::DB_IMG_OPTIMIZE_STATUS_REQUESTED,
1415
+ self::DB_IMG_OPTIMIZE_STATUS_NOTIFIED,
1416
+ self::DB_IMG_OPTIMIZE_STATUS_PULLED,
1417
+ self::DB_IMG_OPTIMIZE_STATUS_ERR,
1418
+ self::DB_IMG_OPTIMIZE_STATUS_ERR_FETCH,
1419
+ self::DB_IMG_OPTIMIZE_STATUS_ERR_OPTM,
1420
+ self::DB_IMG_OPTIMIZE_STATUS_MISS,
1421
+ ) ;
1422
+
1423
+ // The images to check
1424
+ $images_to_check[] = self::DB_IMG_OPTIMIZE_STATUS_XMETA ;
1425
+
1426
+ $count_list = array() ;
1427
+
1428
+ foreach ( $groups_to_check as $v ) {
1429
+ $count_list[ 'group.' . $v ] = $wpdb->get_var( $wpdb->prepare( $q_groups, $v ) ) ;
1430
+ }
1431
+
1432
+ foreach ( $images_to_check as $v ) {
1433
+ $count_list[ 'img.' . $v ] = $wpdb->get_var( $wpdb->prepare( $q, $v ) ) ;
1434
+ }
1435
+
1436
+ $data = array(
1437
'total_img' => $total_img,
1438
'total_not_requested' => $total_not_requested,
1439
) ;
1440
+
1441
+ return array_merge( $data, $count_list ) ;
1442
}
1443
1444
/**
1624
$instance->_img_optimize_rescan() ;
1625
break ;
1626
1627
+ case self::TYPE_IMG_OPTM_DESTROY :
1628
$instance->_img_optimize_destroy() ;
1629
break ;
1630
1631
+ case self::TYPE_IMG_OPTM_DESTROY_UNFINISHED :
1632
+ $instance->_img_optimize_destroy_unfinished() ;
1633
+ break ;
1634
+
1635
case self::TYPE_IMG_PULL :
1636
LiteSpeed_Cache_Log::debug( 'ImgOptm: Manually running Cron pull_optimized_img' ) ;
1637
$result = $instance->_pull_optimized_img( true ) ;
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.1.1.1' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
@@ -120,7 +120,7 @@ class LiteSpeed_Cache
120
// Check if there is a purge request in queue
121
if ( $purge_queue = get_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ) {
122
@header( $purge_queue ) ;
123
- LiteSpeed_Cache_Log::debug( 'Purge Queue found&sent: ' . $purge_queue ) ;
124
delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
125
}
126
@@ -440,7 +440,7 @@ class LiteSpeed_Cache
440
*/
441
public static function footer_hook()
442
{
443
- LiteSpeed_Cache_Log::debug( 'Footer hook called' ) ;
444
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
445
define( 'LITESPEED_FOOTER_CALLED', true ) ;
446
}
@@ -455,22 +455,22 @@ class LiteSpeed_Cache
455
private function _check_is_html( $buffer = null )
456
{
457
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
458
- LiteSpeed_Cache_Log::debug2( 'CHK html bypass: miss footer const' ) ;
459
return ;
460
}
461
462
if ( defined( 'DOING_AJAX' ) ) {
463
- LiteSpeed_Cache_Log::debug2( 'CHK html bypass: doing ajax' ) ;
464
return ;
465
}
466
467
if ( defined( 'DOING_CRON' ) ) {
468
- LiteSpeed_Cache_Log::debug2( 'CHK html bypass: doing cron' ) ;
469
return ;
470
}
471
472
if ( $_SERVER[ 'REQUEST_METHOD' ] !== 'GET' ) {
473
- LiteSpeed_Cache_Log::debug2( 'CHK html bypass: not get method ' . $_SERVER[ 'REQUEST_METHOD' ] ) ;
474
return ;
475
}
476
@@ -489,11 +489,11 @@ class LiteSpeed_Cache
489
$is_html = stripos( $buffer, '<html' ) === 0 || stripos( $buffer, '<!DOCTYPE' ) === 0 ;
490
491
if ( ! $is_html ) {
492
- LiteSpeed_Cache_Log::debug( 'Footer check failed: ' . ob_get_level() . '-' . substr( $buffer, 0, 100 ) ) ;
493
return ;
494
}
495
496
- LiteSpeed_Cache_Log::debug( 'Footer check passed' ) ;
497
498
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
499
define( 'LITESPEED_IS_HTML', true ) ;
@@ -581,7 +581,7 @@ class LiteSpeed_Cache
581
$running_info_showing = ( defined( 'LITESPEED_IS_HTML' ) && LITESPEED_IS_HTML ) || ( defined( 'LSCACHE_IS_ESI' ) && LSCACHE_IS_ESI ) ;
582
if ( defined( 'LSCACHE_ESI_SILENCE' ) ) {
583
$running_info_showing = false ;
584
- LiteSpeed_Cache_Log::debug( 'ESI silence' ) ;
585
}
586
587
if ( $running_info_showing ) {
19
private static $_instance ;
20
21
const PLUGIN_NAME = 'litespeed-cache' ;
22
+ const PLUGIN_VERSION = '2.1.2' ;
23
24
const PAGE_EDIT_HTACCESS = 'lscache-edit-htaccess' ;
25
120
// Check if there is a purge request in queue
121
if ( $purge_queue = get_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ) {
122
@header( $purge_queue ) ;
123
+ LiteSpeed_Cache_Log::debug( '[Boot] Purge Queue found&sent: ' . $purge_queue ) ;
124
delete_option( LiteSpeed_Cache_Purge::PURGE_QUEUE ) ;
125
}
126
440
*/
441
public static function footer_hook()
442
{
443
+ LiteSpeed_Cache_Log::debug( '[Boot] Footer hook called' ) ;
444
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
445
define( 'LITESPEED_FOOTER_CALLED', true ) ;
446
}
455
private function _check_is_html( $buffer = null )
456
{
457
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
458
+ LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: miss footer const' ) ;
459
return ;
460
}
461
462
if ( defined( 'DOING_AJAX' ) ) {
463
+ LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: doing ajax' ) ;
464
return ;
465
}
466
467
if ( defined( 'DOING_CRON' ) ) {
468
+ LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: doing cron' ) ;
469
return ;
470
}
471
472
if ( $_SERVER[ 'REQUEST_METHOD' ] !== 'GET' ) {
473
+ LiteSpeed_Cache_Log::debug2( '[Boot] CHK html bypass: not get method ' . $_SERVER[ 'REQUEST_METHOD' ] ) ;
474
return ;
475
}
476
489
$is_html = stripos( $buffer, '<html' ) === 0 || stripos( $buffer, '<!DOCTYPE' ) === 0 ;
490
491
if ( ! $is_html ) {
492
+ LiteSpeed_Cache_Log::debug( '[Boot] Footer check failed: ' . ob_get_level() . '-' . substr( $buffer, 0, 100 ) ) ;
493
return ;
494
}
495
496
+ LiteSpeed_Cache_Log::debug( '[Boot] Footer check passed' ) ;
497
498
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
499
define( 'LITESPEED_IS_HTML', true ) ;
581
$running_info_showing = ( defined( 'LITESPEED_IS_HTML' ) && LITESPEED_IS_HTML ) || ( defined( 'LSCACHE_IS_ESI' ) && LSCACHE_IS_ESI ) ;
582
if ( defined( 'LSCACHE_ESI_SILENCE' ) ) {
583
$running_info_showing = false ;
584
+ LiteSpeed_Cache_Log::debug( '[Boot] ESI silence' ) ;
585
}
586
587
if ( $running_info_showing ) {
inc/media.class.php CHANGED
@@ -240,7 +240,19 @@ class LiteSpeed_Cache_Media
240
{
241
// This request is for js/css_async.js
242
if ( strpos( $_SERVER[ 'REQUEST_URI' ], self::LAZY_LIB ) !== false ) {
243
- LiteSpeed_Cache_Log::debug( 'Media run lazyload lib' ) ;
244
245
LiteSpeed_Cache_Control::set_cacheable() ;
246
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: lazyload js' ) ;
@@ -248,12 +260,10 @@ class LiteSpeed_Cache_Media
248
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
249
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_LAZY' ) ;
250
251
- $file = LSCWP_DIR . 'js/lazyload.min.js' ;
252
-
253
- header( 'Content-Length: ' . filesize( $file ) ) ;
254
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
255
256
- echo file_get_contents( $file ) ;
257
exit ;
258
}
259
}
@@ -291,16 +301,16 @@ class LiteSpeed_Cache_Media
291
public static function finalize( $content )
292
{
293
if ( defined( 'LITESPEED_NO_LAZY' ) ) {
294
- LiteSpeed_Cache_Log::debug2( 'Media bypass: NO_LAZY const' ) ;
295
return $content ;
296
}
297
298
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
299
- LiteSpeed_Cache_Log::debug2( 'Media bypass: Not frontend HTML type' ) ;
300
return $content ;
301
}
302
303
- LiteSpeed_Cache_Log::debug( 'Media finalize' ) ;
304
305
$instance = self::get_instance() ;
306
$instance->content = $content ;
@@ -317,14 +327,6 @@ class LiteSpeed_Cache_Media
317
*/
318
private function _finalize()
319
{
320
- $cfg_img_lazy = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_MEDIA_IMG_LAZY ) ;
321
- $cfg_iframe_lazy = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY ) ;
322
-
323
- if ( $cfg_img_lazy ) {
324
- list( $src_list, $html_list ) = $this->_parse_img() ;
325
- $html_list_ori = $html_list ;
326
- }
327
-
328
/**
329
* Use webp for optimized images
330
* @since 1.6.2
@@ -333,6 +335,14 @@ class LiteSpeed_Cache_Media
333
$this->_replace_buffer_img_webp() ;
334
}
335
336
// image lazy load
337
if ( $cfg_img_lazy ) {
338
@@ -411,14 +421,14 @@ class LiteSpeed_Cache_Media
411
* @since 1.6
412
*/
413
if ( strpos( $attrs[ 'src' ], 'base64' ) !== false || substr( $attrs[ 'src' ], 0, 5 ) === 'data:' ) {
414
- LiteSpeed_Cache_Log::debug2( 'Media bypassed base64 img' ) ;
415
continue ;
416
}
417
418
- LiteSpeed_Cache_Log::debug2( 'Media: found: ' . $attrs[ 'src' ] ) ;
419
420
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) || ! empty( $attrs[ 'data-srcset' ] ) ) {
421
- LiteSpeed_Cache_Log::debug2( 'Media bypassed' ) ;
422
continue ;
423
}
424
@@ -427,7 +437,7 @@ class LiteSpeed_Cache_Media
427
* @since 1.5
428
*/
429
if ( $excludes && LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'src' ], $excludes ) ) {
430
- LiteSpeed_Cache_Log::debug2( 'Media: lazyload image exclude ' . $attrs[ 'src' ] ) ;
431
continue ;
432
}
433
@@ -463,10 +473,10 @@ class LiteSpeed_Cache_Media
463
continue ;
464
}
465
466
- LiteSpeed_Cache_Log::debug2( 'Media found iframe: ' . $attrs[ 'src' ] ) ;
467
468
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) ) {
469
- LiteSpeed_Cache_Log::debug2( 'Media bypassed' ) ;
470
continue ;
471
}
472
@@ -520,7 +530,7 @@ class LiteSpeed_Cache_Media
520
*/
521
public function webp_attach_img_src( $img )
522
{
523
- LiteSpeed_Cache_Log::debug2( 'Media changing attach src: ' . $img[0] ) ;
524
if ( $img && $url = $this->_replace_webp( $img[ 0 ] ) ) {
525
$img[ 0 ] = $url ;
526
}
@@ -572,19 +582,19 @@ class LiteSpeed_Cache_Media
572
*/
573
private function _replace_webp( $url )
574
{
575
- LiteSpeed_Cache_Log::debug2( 'Media: webp replacing: ' . $url ) ;
576
if ( LiteSpeed_Cache_Utility::is_internal_file( $url ) ) {
577
// check if has webp file
578
if ( LiteSpeed_Cache_Utility::is_internal_file( $url . '.webp' ) ) {
579
$url .= '.webp' ;
580
}
581
else {
582
- LiteSpeed_Cache_Log::debug2( 'Media: no WebP file, bypassed' ) ;
583
return false ;
584
}
585
}
586
else {
587
- LiteSpeed_Cache_Log::debug2( 'Media: no file, bypassed' ) ;
588
return false ;
589
}
590
240
{
241
// This request is for js/css_async.js
242
if ( strpos( $_SERVER[ 'REQUEST_URI' ], self::LAZY_LIB ) !== false ) {
243
+ LiteSpeed_Cache_Log::debug( '[Media] run lazyload lib' ) ;
244
+
245
+ $file = LSCWP_DIR . 'js/lazyload.min.js' ;
246
+
247
+ $content = Litespeed_File::read( $file ) ;
248
+
249
+ $static_file = LSCWP_CONTENT_DIR . '/cache/js/lazyload.js' ;
250
+
251
+ // Save to cache folder to enable directly usage by .htacess
252
+ if ( ! file_exists( $static_file ) ) {
253
+ Litespeed_File::save( $static_file, $content, true ) ;
254
+ LiteSpeed_Cache_Log::debug( '[Media] save lazyload lib to ' . $static_file ) ;
255
+ }
256
257
LiteSpeed_Cache_Control::set_cacheable() ;
258
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: lazyload js' ) ;
260
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
261
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_LAZY' ) ;
262
263
+ header( 'Content-Length: ' . strlen( $content ) ) ;
264
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
265
266
+ echo $content ;
267
exit ;
268
}
269
}
301
public static function finalize( $content )
302
{
303
if ( defined( 'LITESPEED_NO_LAZY' ) ) {
304
+ LiteSpeed_Cache_Log::debug2( '[Media] bypass: NO_LAZY const' ) ;
305
return $content ;
306
}
307
308
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
309
+ LiteSpeed_Cache_Log::debug2( '[Media] bypass: Not frontend HTML type' ) ;
310
return $content ;
311
}
312
313
+ LiteSpeed_Cache_Log::debug( '[Media] finalize' ) ;
314
315
$instance = self::get_instance() ;
316
$instance->content = $content ;
327
*/
328
private function _finalize()
329
{
330
/**
331
* Use webp for optimized images
332
* @since 1.6.2
335
$this->_replace_buffer_img_webp() ;
336
}
337
338
+ $cfg_img_lazy = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_MEDIA_IMG_LAZY ) ;
339
+ $cfg_iframe_lazy = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_MEDIA_IFRAME_LAZY ) ;
340
+
341
+ if ( $cfg_img_lazy ) {
342
+ list( $src_list, $html_list ) = $this->_parse_img() ;
343
+ $html_list_ori = $html_list ;
344
+ }
345
+
346
// image lazy load
347
if ( $cfg_img_lazy ) {
348
421
* @since 1.6
422
*/
423
if ( strpos( $attrs[ 'src' ], 'base64' ) !== false || substr( $attrs[ 'src' ], 0, 5 ) === 'data:' ) {
424
+ LiteSpeed_Cache_Log::debug2( '[Media] bypassed base64 img' ) ;
425
continue ;
426
}
427
428
+ LiteSpeed_Cache_Log::debug2( '[Media] found: ' . $attrs[ 'src' ] ) ;
429
430
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) || ! empty( $attrs[ 'data-srcset' ] ) ) {
431
+ LiteSpeed_Cache_Log::debug2( '[Media] bypassed' ) ;
432
continue ;
433
}
434
437
* @since 1.5
438
*/
439
if ( $excludes && LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'src' ], $excludes ) ) {
440
+ LiteSpeed_Cache_Log::debug2( '[Media] lazyload image exclude ' . $attrs[ 'src' ] ) ;
441
continue ;
442
}
443
473
continue ;
474
}
475
476
+ LiteSpeed_Cache_Log::debug2( '[Media] found iframe: ' . $attrs[ 'src' ] ) ;
477
478
if ( ! empty( $attrs[ 'data-no-lazy' ] ) || ! empty( $attrs[ 'data-lazyloaded' ] ) || ! empty( $attrs[ 'data-src' ] ) ) {
479
+ LiteSpeed_Cache_Log::debug2( '[Media] bypassed' ) ;
480
continue ;
481
}
482
530
*/
531
public function webp_attach_img_src( $img )
532
{
533
+ LiteSpeed_Cache_Log::debug2( '[Media] changing attach src: ' . $img[0] ) ;
534
if ( $img && $url = $this->_replace_webp( $img[ 0 ] ) ) {
535
$img[ 0 ] = $url ;
536
}
582
*/
583
private function _replace_webp( $url )
584
{
585
+ LiteSpeed_Cache_Log::debug2( '[Media] webp replacing: ' . $url ) ;
586
if ( LiteSpeed_Cache_Utility::is_internal_file( $url ) ) {
587
// check if has webp file
588
if ( LiteSpeed_Cache_Utility::is_internal_file( $url . '.webp' ) ) {
589
$url .= '.webp' ;
590
}
591
else {
592
+ LiteSpeed_Cache_Log::debug2( '[Media] no WebP file, bypassed' ) ;
593
return false ;
594
}
595
}
596
else {
597
+ LiteSpeed_Cache_Log::debug2( '[Media] no file, bypassed' ) ;
598
return false ;
599
}
600
inc/optimize.class.php CHANGED
@@ -34,6 +34,7 @@ class LiteSpeed_Cache_Optimize
34
private $cfg_exc_jquery ;
35
private $cfg_ggfonts_async ;
36
private $cfg_optm_max_size ;
37
38
private $dns_prefetch ;
39
@@ -69,6 +70,7 @@ class LiteSpeed_Cache_Optimize
69
$this->cfg_exc_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY ) ;
70
$this->cfg_ggfonts_async = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_ASYNC ) ;
71
$this->cfg_optm_max_size = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_MAX_SIZE ) * 1000000 ;
72
73
$this->_static_request_check() ;
74
@@ -181,7 +183,19 @@ class LiteSpeed_Cache_Optimize
181
{
182
// This request is for js/css_async.js
183
if ( ( $this->cfg_css_async || $this->cfg_ggfonts_async ) && strpos( $_SERVER[ 'REQUEST_URI' ], self::CSS_ASYNC_LIB ) !== false ) {
184
- LiteSpeed_Cache_Log::debug( 'Optimizer start serving static file' ) ;
185
186
LiteSpeed_Cache_Control::set_cacheable() ;
187
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: css async js' ) ;
@@ -189,12 +203,10 @@ class LiteSpeed_Cache_Optimize
189
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
190
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_CSS_ASYNC' ) ;
191
192
- $file = LSCWP_DIR . 'js/css_async.min.js' ;
193
-
194
- header( 'Content-Length: ' . filesize( $file ) ) ;
195
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
196
197
- echo file_get_contents( $file ) ;
198
exit ;
199
}
200
@@ -212,70 +224,69 @@ class LiteSpeed_Cache_Optimize
212
return ;
213
}
214
215
- LiteSpeed_Cache_Log::debug( 'Optimizer start minifying file' ) ;
216
217
// Proceed css/js file generation
218
define( 'LITESPEED_MIN_FILE', true ) ;
219
220
- $file_type = substr( $match[ 1 ], strrpos( $match[ 1 ], '.' ) + 1 ) ;
221
-
222
- $ttl = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ) ;
223
224
- // Load file from file based cache if not enabled lscache
225
- if ( ! defined( 'LITESPEED_ON' ) ) {
226
- LiteSpeed_Cache_Log::debug( '[Optimize] Not enabled lscache, using file based cache' ) ;
227
228
- $static_file = LSCWP_CONTENT_DIR . '/cache/' . $file_type . '/' . $match[ 1 ] ;
229
- if ( file_exists( $static_file ) && time() - filemtime( $static_file ) <= $ttl ) {
230
- $content = Litespeed_File::read( $static_file ) ;
231
232
- // Output header first
233
- $headers = array() ;
234
- $headers[ 'Content-Length' ] = strlen( $content ) ;
235
236
- if ( $file_type === 'css' ) {
237
- $headers[ 'Content-Type' ] = 'text/css; charset=utf-8' ;
238
- }
239
- else {
240
- $headers[ 'Content-Type' ] = 'application/x-javascript' ;
241
- }
242
243
- foreach ( $headers as $k => $v ) {
244
- header( $k . ': ' . $v ) ;
245
- LiteSpeed_Cache_Log::debug( '[Optimize] HEADER ' . $k . ': ' . $v ) ;
246
- }
247
248
- echo $content ;
249
- exit ;
250
- }
251
}
252
-
253
- $concat_only = ! ( $file_type === 'css' ? $this->cfg_css_minify : $this->cfg_js_minify ) ;
254
-
255
- $content = LiteSpeed_Cache_Optimizer::get_instance()->serve( $match[ 1 ], $concat_only ) ;
256
-
257
- if ( ! $content ) {
258
- LiteSpeed_Cache_Control::set_nocache( 'Empty content from optimizer' ) ;
259
- exit ;
260
}
261
262
- // Save to file if not enabled lscache
263
- if ( ! defined( 'LITESPEED_ON' ) ) {
264
- LiteSpeed_Cache_Log::debug( '[Optimize] Saved cache to file [path] ' . $static_file ) ;
265
-
266
- Litespeed_File::save( $static_file, $content, true ) ;
267
- }
268
269
LiteSpeed_Cache_Control::set_cacheable() ;
270
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: min file ' . $match[ 1 ] ) ;
271
LiteSpeed_Cache_Control::set_no_vary() ;
272
- LiteSpeed_Cache_Control::set_custom_ttl( $ttl ) ;
273
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN ) ;
274
275
echo $content ;
276
exit ;
277
}
278
279
/**
280
* Delete file-based cache folder
281
*
@@ -349,7 +360,7 @@ class LiteSpeed_Cache_Optimize
349
}
350
351
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
352
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: Not frontend HTML type' ) ;
353
return $content ;
354
}
355
@@ -358,19 +369,19 @@ class LiteSpeed_Cache_Optimize
358
if ( ! empty( $excludes ) ) {
359
$result = LiteSpeed_Cache_Utility::str_hit_array( esc_url( $_SERVER[ 'REQUEST_URI' ] ), explode( "\n", $excludes ) ) ;
360
if ( $result ) {
361
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: hit URI Excludes setting: ' . $result ) ;
362
return $content ;
363
}
364
}
365
366
// Check if is exclude optm roles ( Need to set Vary too )
367
if ( $result = LiteSpeed_Cache_Config::get_instance()->in_exclude_optimization_roles() ) {
368
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: hit Role Excludes setting: ' . $result ) ;
369
return $content ;
370
}
371
372
373
- LiteSpeed_Cache_Log::debug( 'Optimizer start' ) ;
374
375
$instance = self::get_instance() ;
376
$instance->content = $content ;
@@ -388,7 +399,7 @@ class LiteSpeed_Cache_Optimize
388
private function _optimize()
389
{
390
if ( ! $this->_can_optm() ) {
391
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: admin/feed/preview' ) ;
392
return ;
393
}
394
@@ -492,7 +503,7 @@ class LiteSpeed_Cache_Optimize
492
continue ;
493
}
494
495
- LiteSpeed_Cache_Log::debug( 'Optm: google fonts async loading: ' . $src_list[ $k ] ) ;
496
}
497
// async html
498
$html_list_async = $this->_async_css_list( $html_list ) ;
@@ -662,7 +673,7 @@ class LiteSpeed_Cache_Optimize
662
$this->content .= "\n" . '<!-- Page optimized by LiteSpeed Cache on '.date('Y-m-d H:i:s').' -->' ;
663
664
} catch ( ErrorException $e ) {
665
- LiteSpeed_Cache_Log::debug( 'Error when optimizing HTML: ' . $e->getMessage() ) ;
666
error_log( 'LiteSpeed Optimizer optimizing HTML Error: ' . $e->getMessage() ) ;
667
// If failed to minify HTML, restore original content
668
$this->content = $ori ;
@@ -759,7 +770,7 @@ class LiteSpeed_Cache_Optimize
759
}
760
}
761
if ( count( $src_arr ) > 1 ) {
762
- LiteSpeed_Cache_Log::debug( 'Optimizer: separate ' . $file_type . ' to ' . count( $src_arr ) ) ;
763
}
764
765
// group build
@@ -831,7 +842,7 @@ class LiteSpeed_Cache_Optimize
831
832
// Analyse links
833
foreach ( $src_list as $key => $src ) {
834
- LiteSpeed_Cache_Log::debug2( 'Optm: ' . $src ) ;
835
836
/**
837
* Excluded links won't be done any optm
@@ -839,14 +850,14 @@ class LiteSpeed_Cache_Optimize
839
*/
840
// if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $src, $excludes ) ) {
841
// $ignored_html[] = $html_list[ $key ] ;
842
- // LiteSpeed_Cache_Log::debug2( 'Optm: Abort excludes: ' . $exclude ) ;
843
// continue ;
844
// }
845
846
// Check if has no-optimize attr
847
if ( strpos( $html_list[ $key ], 'data-no-optimize' ) !== false ) {
848
$ignored_html[] = $html_list[ $key ] ;
849
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort excludes: attr data-no-optimize' ) ;
850
continue ;
851
}
852
@@ -854,7 +865,7 @@ class LiteSpeed_Cache_Optimize
854
$url_parsed = parse_url( $src ) ;
855
if ( ! $file_info = LiteSpeed_Cache_Utility::is_internal_file( $src ) ) {
856
$ignored_html[ $src ] = $html_list[ $key ] ;
857
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort external/non-exist' ) ;
858
continue ;
859
}
860
@@ -865,7 +876,7 @@ class LiteSpeed_Cache_Optimize
865
*/
866
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
867
$ignored_html[ $src ] = $html_list[ $key ] ;
868
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort jQuery by setting' ) ;
869
870
// Add to HTTP2 as its ignored but still internal src
871
$this->append_http2( $src, 'js' ) ;
@@ -896,6 +907,7 @@ class LiteSpeed_Cache_Optimize
896
if ( ! is_array( $src ) ) {
897
$src = array( $src ) ;
898
}
899
$src = array_values( $src ) ;
900
901
$hash = md5( serialize( $src ) ) ;
@@ -918,6 +930,21 @@ class LiteSpeed_Cache_Optimize
918
LiteSpeed_Cache_Data::optm_save_src( $short . '.' . $file_type, $src ) ;
919
}
920
921
$file_to_save = self::DIR_MIN . '/' . $filename . '.' . $file_type ;
922
923
return LiteSpeed_Cache_Utility::get_permalink_url( $file_to_save ) ;
@@ -967,7 +994,7 @@ class LiteSpeed_Cache_Optimize
967
}
968
// todo @v2.0: allow defer even exclude from optm
969
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'src' ], $excludes ) ) {
970
- LiteSpeed_Cache_Log::debug2( 'Optm: _parse_js bypassed exclude ' . $exclude ) ;
971
continue ;
972
}
973
@@ -1027,13 +1054,13 @@ class LiteSpeed_Cache_Optimize
1027
}
1028
1029
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $excludes ) ) {
1030
- LiteSpeed_Cache_Log::debug2( 'Optm: _handle_css bypassed exclude ' . $exclude ) ;
1031
continue ;
1032
}
1033
1034
// Check if need to remove this css
1035
if ( $this->css_to_be_removed && LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $this->css_to_be_removed ) ) {
1036
- LiteSpeed_Cache_Log::debug( 'Optm: rm css snippet ' . $attrs[ 'href' ] ) ;
1037
// Delete this css snippet from orig html
1038
$this->content = str_replace( $match[ 0 ], '', $this->content ) ;
1039
continue ;
@@ -1063,12 +1090,12 @@ class LiteSpeed_Cache_Optimize
1063
{
1064
foreach ( $html_list as $k => $ori ) {
1065
if ( strpos( $ori, 'data-asynced' ) !== false ) {
1066
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr data-asynced exist' ) ;
1067
continue ;
1068
}
1069
1070
if ( strpos( $ori, 'data-no-async' ) !== false ) {
1071
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr api data-no-async' ) ;
1072
continue ;
1073
}
1074
@@ -1098,11 +1125,11 @@ class LiteSpeed_Cache_Optimize
1098
continue ;
1099
}
1100
if ( strpos( $v, 'data-deferred' ) !== false ) {
1101
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr data-deferred exist' ) ;
1102
continue ;
1103
}
1104
if ( strpos( $v, 'data-no-defer' ) !== false ) {
1105
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr api data-no-defer' ) ;
1106
continue ;
1107
}
1108
@@ -1114,14 +1141,14 @@ class LiteSpeed_Cache_Optimize
1114
// parse js src
1115
preg_match( '#<script \s*([^>]+)>#isU', $v, $matches ) ;
1116
if ( empty( $matches[ 1 ] ) ) {
1117
- LiteSpeed_Cache_Log::debug( 'Optm: js defer parse html failed: ' . $v ) ;
1118
continue ;
1119
}
1120
1121
$attrs = LiteSpeed_Cache_Utility::parse_attr( $matches[ 1 ] ) ;
1122
1123
if ( empty( $attrs[ 'src' ] ) ) {
1124
- LiteSpeed_Cache_Log::debug( 'Optm: js defer parse src failed: ' . $matches[ 1 ] ) ;
1125
continue ;
1126
}
1127
@@ -1133,7 +1160,7 @@ class LiteSpeed_Cache_Optimize
1133
* @since 1.5
1134
*/
1135
if ( $this->cfg_js_defer_exc && LiteSpeed_Cache_Utility::str_hit_array( $src, $this->cfg_js_defer_exc ) ) {
1136
- LiteSpeed_Cache_Log::debug( 'Optm: js defer exclude ' . $src ) ;
1137
continue ;
1138
}
1139
@@ -1142,7 +1169,7 @@ class LiteSpeed_Cache_Optimize
1142
* @since 1.5
1143
*/
1144
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
1145
- LiteSpeed_Cache_Log::debug2( 'Optm: js defer Abort jQuery by setting' ) ;
1146
continue ;
1147
}
1148
34
private $cfg_exc_jquery ;
35
private $cfg_ggfonts_async ;
36
private $cfg_optm_max_size ;
37
+ private $cfg_ttl ;
38
39
private $dns_prefetch ;
40
70
$this->cfg_exc_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY ) ;
71
$this->cfg_ggfonts_async = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_ASYNC ) ;
72
$this->cfg_optm_max_size = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_MAX_SIZE ) * 1000000 ;
73
+ $this->cfg_ttl = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ) ;
74
75
$this->_static_request_check() ;
76
183
{
184
// This request is for js/css_async.js
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
+
194
+ // Save to cache folder to enable directly usage by .htacess
195
+ if ( ! file_exists( $static_file ) ) {
196
+ Litespeed_File::save( $static_file, $content, true ) ;
197
+ LiteSpeed_Cache_Log::debug( '[Optm] save css_async lib to ' . $static_file ) ;
198
+ }
199
200
LiteSpeed_Cache_Control::set_cacheable() ;
201
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: css async js' ) ;
203
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
204
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_CSS_ASYNC' ) ;
205
206
+ header( 'Content-Length: ' . strlen( $content ) ) ;
207
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
208
209
+ echo $content ;
210
exit ;
211
}
212
224
return ;
225
}
226
227
+ LiteSpeed_Cache_Log::debug( '[Optm] start minifying file' ) ;
228
229
// Proceed css/js file generation
230
define( 'LITESPEED_MIN_FILE', true ) ;
231
232
+ $file_type = $match[ 2 ] ;
233
234
+ $static_file = LSCWP_CONTENT_DIR . '/cache/' . $file_type . '/' . $match[ 1 ] ;
235
236
+ $headers = array() ;
237
+ if ( $file_type === 'css' ) {
238
+ $headers[ 'Content-Type' ] = 'text/css; charset=utf-8' ;
239
+ }
240
+ else {
241
+ $headers[ 'Content-Type' ] = 'application/x-javascript' ;
242
+ }
243
244
+ // Even if hit PHP, still check if the file is valid to bypass minify process
245
+ if ( ! file_exists( $static_file ) || time() - filemtime( $static_file ) > $this->cfg_ttl ) {
246
+ $concat_only = ! ( $file_type === 'css' ? $this->cfg_css_minify : $this->cfg_js_minify ) ;
247
248
+ $content = LiteSpeed_Cache_Optimizer::get_instance()->serve( $match[ 1 ], $concat_only ) ;
249
250
+ // Generate static file
251
+ Litespeed_File::save( $static_file, $content, true ) ;
252
+ LiteSpeed_Cache_Log::debug( '[Optm] Saved cache to file [path] ' . $static_file ) ;
253
254
}
255
+ else {
256
+ // Load file from file based cache if not expired
257
+ LiteSpeed_Cache_Log::debug( '[Optm] Static file available' ) ;
258
+ $content = Litespeed_File::read( $static_file ) ;
259
}
260
261
+ // Output header first
262
+ $headers[ 'Content-Length' ] = strlen( $content ) ;
263
+ $this->_output_header( $headers ) ;
264
265
LiteSpeed_Cache_Control::set_cacheable() ;
266
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: min file ' . $match[ 1 ] ) ;
267
LiteSpeed_Cache_Control::set_no_vary() ;
268
+ LiteSpeed_Cache_Control::set_custom_ttl( $this->cfg_ttl ) ;
269
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN ) ;
270
271
echo $content ;
272
exit ;
273
}
274
275
+ /**
276
+ * Output header info
277
+ *
278
+ * @since 2.1.2
279
+ * @access public
280
+ */
281
+ private function _output_header( $headers )
282
+ {
283
+ foreach ( $headers as $k => $v ) {
284
+ header( $k . ': ' . $v ) ;
285
+ LiteSpeed_Cache_Log::debug( '[Optm] HEADER ' . $k . ': ' . $v ) ;
286
+ }
287
+
288
+ }
289
+
290
/**
291
* Delete file-based cache folder
292
*
360
}
361
362
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
363
+ LiteSpeed_Cache_Log::debug( '[Optm] bypass: Not frontend HTML type' ) ;
364
return $content ;
365
}
366
369
if ( ! empty( $excludes ) ) {
370
$result = LiteSpeed_Cache_Utility::str_hit_array( esc_url( $_SERVER[ 'REQUEST_URI' ] ), explode( "\n", $excludes ) ) ;
371
if ( $result ) {
372
+ LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit URI Excludes setting: ' . $result ) ;
373
return $content ;
374
}
375
}
376
377
// Check if is exclude optm roles ( Need to set Vary too )
378
if ( $result = LiteSpeed_Cache_Config::get_instance()->in_exclude_optimization_roles() ) {
379
+ LiteSpeed_Cache_Log::debug( '[Optm] bypass: hit Role Excludes setting: ' . $result ) ;
380
return $content ;
381
}
382
383
384
+ LiteSpeed_Cache_Log::debug( '[Optm] start' ) ;
385
386
$instance = self::get_instance() ;
387
$instance->content = $content ;
399
private function _optimize()
400
{
401
if ( ! $this->_can_optm() ) {
402
+ LiteSpeed_Cache_Log::debug( '[Optm] bypass: admin/feed/preview' ) ;
403
return ;
404
}
405
503
continue ;
504
}
505
506
+ LiteSpeed_Cache_Log::debug( '[Optm] google fonts async loading: ' . $src_list[ $k ] ) ;
507
}
508
// async html
509
$html_list_async = $this->_async_css_list( $html_list ) ;
673
$this->content .= "\n" . '<!-- Page optimized by LiteSpeed Cache on '.date('Y-m-d H:i:s').' -->' ;
674
675
} catch ( ErrorException $e ) {
676
+ LiteSpeed_Cache_Log::debug( '[Optm] Error when optimizing HTML: ' . $e->getMessage() ) ;
677
error_log( 'LiteSpeed Optimizer optimizing HTML Error: ' . $e->getMessage() ) ;
678
// If failed to minify HTML, restore original content
679
$this->content = $ori ;
770
}
771
}
772
if ( count( $src_arr ) > 1 ) {
773
+ LiteSpeed_Cache_Log::debug( '[Optm] separate ' . $file_type . ' to ' . count( $src_arr ) ) ;
774
}
775
776
// group build
842
843
// Analyse links
844
foreach ( $src_list as $key => $src ) {
845
+ LiteSpeed_Cache_Log::debug2( '[Optm] ' . $src ) ;
846
847
/**
848
* Excluded links won't be done any optm
850
*/
851
// if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $src, $excludes ) ) {
852
// $ignored_html[] = $html_list[ $key ] ;
853
+ // LiteSpeed_Cache_Log::debug2( '[Optm]: Abort excludes: ' . $exclude ) ;
854
// continue ;
855
// }
856
857
// Check if has no-optimize attr
858
if ( strpos( $html_list[ $key ], 'data-no-optimize' ) !== false ) {
859
$ignored_html[] = $html_list[ $key ] ;
860
+ LiteSpeed_Cache_Log::debug2( '[Optm] Abort excludes: attr data-no-optimize' ) ;
861
continue ;
862
}
863
865
$url_parsed = parse_url( $src ) ;
866
if ( ! $file_info = LiteSpeed_Cache_Utility::is_internal_file( $src ) ) {
867
$ignored_html[ $src ] = $html_list[ $key ] ;
868
+ LiteSpeed_Cache_Log::debug2( '[Optm] Abort external/non-exist' ) ;
869
continue ;
870
}
871
876
*/
877
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
878
$ignored_html[ $src ] = $html_list[ $key ] ;
879
+ LiteSpeed_Cache_Log::debug2( '[Optm] Abort jQuery by setting' ) ;
880
881
// Add to HTTP2 as its ignored but still internal src
882
$this->append_http2( $src, 'js' ) ;
907
if ( ! is_array( $src ) ) {
908
$src = array( $src ) ;
909
}
910
+
911
$src = array_values( $src ) ;
912
913
$hash = md5( serialize( $src ) ) ;
930
LiteSpeed_Cache_Data::optm_save_src( $short . '.' . $file_type, $src ) ;
931
}
932
933
+ // Generate static files
934
+ $static_file = LSCWP_CONTENT_DIR . "/cache/$file_type/$filename.$file_type" ;
935
+ // Check if the file is valid to bypass minify process
936
+ if ( ! file_exists( $static_file ) || time() - filemtime( $static_file ) > $this->cfg_ttl ) {
937
+ $concat_only = ! ( $file_type === 'css' ? $this->cfg_css_minify : $this->cfg_js_minify ) ;
938
+
939
+ $content = LiteSpeed_Cache_Optimizer::get_instance()->serve( $src, $concat_only ) ;
940
+
941
+ // Generate static file
942
+ Litespeed_File::save( $static_file, $content, true ) ;
943
+
944
+ LiteSpeed_Cache_Log::debug( '[Optm] Saved static file [path] ' . $static_file ) ;
945
+
946
+ }
947
+
948
$file_to_save = self::DIR_MIN . '/' . $filename . '.' . $file_type ;
949
950
return LiteSpeed_Cache_Utility::get_permalink_url( $file_to_save ) ;
994
}
995
// todo @v2.0: allow defer even exclude from optm
996
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'src' ], $excludes ) ) {
997
+ LiteSpeed_Cache_Log::debug2( '[Optm] _parse_js bypassed exclude ' . $exclude ) ;
998
continue ;
999
}
1000
1054
}
1055
1056
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $excludes ) ) {
1057
+ LiteSpeed_Cache_Log::debug2( '[Optm] _handle_css bypassed exclude ' . $exclude ) ;
1058
continue ;
1059
}
1060
1061
// Check if need to remove this css
1062
if ( $this->css_to_be_removed && LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $this->css_to_be_removed ) ) {
1063
+ LiteSpeed_Cache_Log::debug( '[Optm] rm css snippet ' . $attrs[ 'href' ] ) ;
1064
// Delete this css snippet from orig html
1065
$this->content = str_replace( $match[ 0 ], '', $this->content ) ;
1066
continue ;
1090
{
1091
foreach ( $html_list as $k => $ori ) {
1092
if ( strpos( $ori, 'data-asynced' ) !== false ) {
1093
+ LiteSpeed_Cache_Log::debug2( '[Optm] bypass: attr data-asynced exist' ) ;
1094
continue ;
1095
}
1096
1097
if ( strpos( $ori, 'data-no-async' ) !== false ) {
1098
+ LiteSpeed_Cache_Log::debug2( '[Optm] bypass: attr api data-no-async' ) ;
1099
continue ;
1100
}
1101
1125
continue ;
1126
}
1127
if ( strpos( $v, 'data-deferred' ) !== false ) {
1128
+ LiteSpeed_Cache_Log::debug2( '[Optm] bypass: attr data-deferred exist' ) ;
1129
continue ;
1130
}
1131
if ( strpos( $v, 'data-no-defer' ) !== false ) {
1132
+ LiteSpeed_Cache_Log::debug2( '[Optm] bypass: attr api data-no-defer' ) ;
1133
continue ;
1134
}
1135
1141
// parse js src
1142
preg_match( '#<script \s*([^>]+)>#isU', $v, $matches ) ;
1143
if ( empty( $matches[ 1 ] ) ) {
1144
+ LiteSpeed_Cache_Log::debug( '[Optm] js defer parse html failed: ' . $v ) ;
1145
continue ;
1146
}
1147
1148
$attrs = LiteSpeed_Cache_Utility::parse_attr( $matches[ 1 ] ) ;
1149
1150
if ( empty( $attrs[ 'src' ] ) ) {
1151
+ LiteSpeed_Cache_Log::debug( '[Optm] js defer parse src failed: ' . $matches[ 1 ] ) ;
1152
continue ;
1153
}
1154
1160
* @since 1.5
1161
*/
1162
if ( $this->cfg_js_defer_exc && LiteSpeed_Cache_Utility::str_hit_array( $src, $this->cfg_js_defer_exc ) ) {
1163
+ LiteSpeed_Cache_Log::debug( '[Optm] js defer exclude ' . $src ) ;
1164
continue ;
1165
}
1166
1169
* @since 1.5
1170
*/
1171
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
1172
+ LiteSpeed_Cache_Log::debug2( '[Optm] js defer Abort jQuery by setting' ) ;
1173
continue ;
1174
}
1175
inc/optimizer.class.php CHANGED
@@ -65,12 +65,16 @@ class LiteSpeed_Cache_Optimizer
65
*/
66
public function serve( $filename, $concat_only )
67
{
68
- // Search filename in db for src URLs
69
- $urls = LiteSpeed_Cache_Data::optm_hash2src( $filename ) ;
70
- if ( ! $urls || ! is_array( $urls ) ) {
71
- return false;
72
}
73
-
74
75
// Parse real file path
76
$real_files = array() ;
@@ -86,26 +90,25 @@ class LiteSpeed_Cache_Optimizer
86
return false;
87
}
88
89
90
set_error_handler( 'litespeed_exception_handler' ) ;
91
92
- $headers = array() ;
93
$content = '' ;
94
- $file_type = substr( $filename, strrpos( $filename, '.' ) + 1 ) ;
95
try {
96
// Handle CSS
97
if ( $file_type === 'css' ) {
98
$content = $this->_serve_css( $real_files, $concat_only ) ;
99
- $headers[ 'Content-Type' ] = 'text/css; charset=utf-8' ;
100
}
101
// Handle JS
102
else {
103
$content = $this->_serve_js( $real_files, $concat_only ) ;
104
- $headers[ 'Content-Type' ] = 'application/x-javascript' ;
105
}
106
107
} catch ( ErrorException $e ) {
108
- LiteSpeed_Cache_Log::debug( 'Error when serving from optimizer: ' . $e->getMessage() ) ;
109
error_log( 'LiteSpeed Optimizer serving Error: ' . $e->getMessage() ) ;
110
return false ;
111
}
@@ -119,14 +122,7 @@ class LiteSpeed_Cache_Optimizer
119
$content = $this->_remove_comment( $content, $file_type ) ;
120
}
121
122
- LiteSpeed_Cache_Log::debug( 'Optm: Generated content' ) ;
123
-
124
- $headers[ 'Content-Length' ] = strlen( $content ) ;
125
-
126
- foreach ( $headers as $key => $val ) {
127
- header( $key . ': ' . $val ) ;
128
- LiteSpeed_Cache_Log::debug( 'HEADER ' . $key . ': ' . $val ) ;
129
- }
130
131
return $content ;
132
}
@@ -141,8 +137,8 @@ class LiteSpeed_Cache_Optimizer
141
{
142
$con = array() ;
143
foreach ( $files as $real_path ) {
144
- LiteSpeed_Cache_Log::debug( 'Optimizer: [real_path] ' . $real_path ) ;
145
- $data = $this->_read( $real_path ) ;
146
147
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
148
@@ -169,7 +165,7 @@ class LiteSpeed_Cache_Optimizer
169
{
170
$con = array() ;
171
foreach ( $files as $real_path ) {
172
- $data = $this->_read( $real_path ) ;
173
174
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
175
$data = JSMin\JSMin::minify( $data ) ;
@@ -207,21 +203,6 @@ class LiteSpeed_Cache_Optimizer
207
return false ;
208
}
209
210
- /**
211
- * Read content and remove UTF-8 BOM if present
212
- *
213
- * @since 1.9
214
- * @access private
215
- */
216
- private function _read( $file )
217
- {
218
- $content = file_get_contents( $file ) ;
219
- if ( substr( $content, 0, 3 ) === "\xEF\xBB\xBF" ) {
220
- $content = substr( $content, 3 ) ;
221
- }
222
- return $content ;
223
- }
224
-
225
/**
226
* Remove comment when minify
227
*
65
*/
66
public function serve( $filename, $concat_only )
67
{
68
+ if ( ! is_array( $filename ) ) {
69
+ // Search filename in db for src URLs
70
+ $urls = LiteSpeed_Cache_Data::optm_hash2src( $filename ) ;
71
+ if ( ! $urls || ! is_array( $urls ) ) {
72
+ return false;
73
+ }
74
+ }
75
+ else {
76
+ $urls = $filename ;
77
}
78
79
// Parse real file path
80
$real_files = array() ;
90
return false;
91
}
92
93
+ LiteSpeed_Cache_Log::debug2( '[Optmer] urls : ', $urls ) ;
94
95
set_error_handler( 'litespeed_exception_handler' ) ;
96
97
$content = '' ;
98
+ $tmp = parse_url( $urls[ 0 ], PHP_URL_PATH ) ;
99
+ $file_type = substr( $tmp, strrpos( $tmp, '.' ) + 1 ) ;
100
try {
101
// Handle CSS
102
if ( $file_type === 'css' ) {
103
$content = $this->_serve_css( $real_files, $concat_only ) ;
104
}
105
// Handle JS
106
else {
107
$content = $this->_serve_js( $real_files, $concat_only ) ;
108
}
109
110
} catch ( ErrorException $e ) {
111
+ LiteSpeed_Cache_Log::debug( '[Optmer] Error when serving from optimizer: ' . $e->getMessage() ) ;
112
error_log( 'LiteSpeed Optimizer serving Error: ' . $e->getMessage() ) ;
113
return false ;
114
}
122
$content = $this->_remove_comment( $content, $file_type ) ;
123
}
124
125
+ LiteSpeed_Cache_Log::debug( '[Optmer] Generated content ' . $file_type ) ;
126
127
return $content ;
128
}
137
{
138
$con = array() ;
139
foreach ( $files as $real_path ) {
140
+ LiteSpeed_Cache_Log::debug( '[Optmer] [real_path] ' . $real_path ) ;
141
+ $data = Litespeed_File::read( $real_path ) ;
142
143
$data = preg_replace( '/@charset[^;]+;\\s*/', '', $data ) ;
144
165
{
166
$con = array() ;
167
foreach ( $files as $real_path ) {
168
+ $data = Litespeed_File::read( $real_path ) ;
169
170
if ( ! $concat_only && ! $this->_is_min( $real_path ) ) {
171
$data = JSMin\JSMin::minify( $data ) ;
203
return false ;
204
}
205
206
/**
207
* Remove comment when minify
208
*
inc/vary.class.php CHANGED
@@ -331,7 +331,7 @@ class LiteSpeed_Cache_Vary
331
// Get admin bar set
332
// see @_get_admin_bar_pref()
333
$pref = get_user_option( 'show_admin_bar_front', $uid ) ;
334
- LiteSpeed_Cache_Log::debug2( 'Vary: show_admin_bar_front: ' . $pref ) ;
335
$admin_bar = $pref === false || $pref === 'true' ;
336
337
if ( $admin_bar ) {
@@ -509,7 +509,7 @@ class LiteSpeed_Cache_Vary
509
}
510
511
if ( empty($tp_cookies) ) {
512
- LiteSpeed_Cache_Log::debug2( 'Vary: no custimzed vary ' ) ;
513
return ;
514
}
515
331
// Get admin bar set
332
// see @_get_admin_bar_pref()
333
$pref = get_user_option( 'show_admin_bar_front', $uid ) ;
334
+ LiteSpeed_Cache_Log::debug2( '[Vary] show_admin_bar_front: ' . $pref ) ;
335
$admin_bar = $pref === false || $pref === 'true' ;
336
337
if ( $admin_bar ) {
509
}
510
511
if ( empty($tp_cookies) ) {
512
+ LiteSpeed_Cache_Log::debug2( '[Vary] no custimzed vary ' ) ;
513
return ;
514
}
515
includes/litespeed-cache-config.class.php CHANGED
@@ -379,7 +379,7 @@ class LiteSpeed_Cache_Config
379
return $this->options[$id] ;
380
}
381
382
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( 'Invalid option ID ' . $id ) ;
383
384
return NULL ;
385
}
@@ -469,7 +469,7 @@ class LiteSpeed_Cache_Config
469
}
470
471
if ( $group ) {
472
- LiteSpeed_Cache_Log::debug2( 'Config: role in vary_group [group] ' . $group ) ;
473
}
474
475
return $group ;
@@ -919,7 +919,7 @@ class LiteSpeed_Cache_Config
919
self::ITEM_CDN_MAPPING_FILETYPE => $this->options[ 'cdn_filetype' ],
920
) ;
921
update_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array( $cdn_mapping ) ) ;
922
- LiteSpeed_Cache_Log::debug( "Config: plugin_upgrade option adding CDN map" ) ;
923
}
924
925
$this->options = self::option_diff( $default_options, $this->options ) ;
@@ -927,7 +927,7 @@ class LiteSpeed_Cache_Config
927
$res = $this->update_options() ;
928
define( 'LSWCP_EMPTYCACHE', true ) ;// clear all sites caches
929
LiteSpeed_Cache_Purge::purge_all() ;
930
- LiteSpeed_Cache_Log::debug( "Config: plugin_upgrade option changed = $res" ) ;
931
932
// Update img_optm table data for upgrading
933
LiteSpeed_Cache_Data::get_instance() ;
@@ -952,7 +952,7 @@ class LiteSpeed_Cache_Config
952
953
$res = update_site_option( self::OPTION_NAME, $options ) ;
954
955
- LiteSpeed_Cache_Log::debug( "plugin_upgrade option changed = $res\n" ) ;
956
}
957
958
/**
@@ -1026,7 +1026,7 @@ class LiteSpeed_Cache_Config
1026
1027
$res = add_option( self::OPTION_NAME, $this->get_default_options() ) ;
1028
1029
- defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[Config] plugin_activation update option = " . var_export( $res, true ) ) ;
1030
1031
$disable_lscache = false ;
1032
379
return $this->options[$id] ;
380
}
381
382
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( '[Cfg] Invalid option ID ' . $id ) ;
383
384
return NULL ;
385
}
469
}
470
471
if ( $group ) {
472
+ LiteSpeed_Cache_Log::debug2( '[Cfg] role in vary_group [group] ' . $group ) ;
473
}
474
475
return $group ;
919
self::ITEM_CDN_MAPPING_FILETYPE => $this->options[ 'cdn_filetype' ],
920
) ;
921
update_option( LiteSpeed_Cache_Config::ITEM_CDN_MAPPING, array( $cdn_mapping ) ) ;
922
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option adding CDN map" ) ;
923
}
924
925
$this->options = self::option_diff( $default_options, $this->options ) ;
927
$res = $this->update_options() ;
928
define( 'LSWCP_EMPTYCACHE', true ) ;// clear all sites caches
929
LiteSpeed_Cache_Purge::purge_all() ;
930
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option changed = $res" ) ;
931
932
// Update img_optm table data for upgrading
933
LiteSpeed_Cache_Data::get_instance() ;
952
953
$res = update_site_option( self::OPTION_NAME, $options ) ;
954
955
+ LiteSpeed_Cache_Log::debug( "[Cfg] plugin_upgrade option changed = $res\n" ) ;
956
}
957
958
/**
1026
1027
$res = add_option( self::OPTION_NAME, $this->get_default_options() ) ;
1028
1029
+ defined( 'LSCWP_LOG' ) && LiteSpeed_Cache_Log::debug( "[Cfg] plugin_activation update option = " . var_export( $res, true ) ) ;
1030
1031
$disable_lscache = false ;
1032
includes/litespeed-cache-control.class.php CHANGED
@@ -101,7 +101,7 @@ class LiteSpeed_Cache_Control
101
return ;
102
}
103
self::$_control |= self::BM_NO_VARY ;
104
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> no-vary', 3 ) ;
105
}
106
107
/**
@@ -127,7 +127,7 @@ class LiteSpeed_Cache_Control
127
return ;
128
}
129
self::$_control |= self::BM_STALE ;
130
- LiteSpeed_Cache_Log::debug('X Cache_control -> stale') ;
131
}
132
133
/**
@@ -158,7 +158,7 @@ class LiteSpeed_Cache_Control
158
if ( $reason ) {
159
$reason = "( $reason )" ;
160
}
161
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> shared ' . $reason ) ;
162
}
163
164
/**
@@ -188,7 +188,7 @@ class LiteSpeed_Cache_Control
188
if ( $reason ) {
189
$reason = "( $reason )" ;
190
}
191
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> public forced ' . $reason ) ;
192
}
193
194
/**
@@ -218,7 +218,7 @@ class LiteSpeed_Cache_Control
218
if ( $reason ) {
219
$reason = "( $reason )" ;
220
}
221
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> private ' . $reason ) ;
222
}
223
224
/**
@@ -241,7 +241,7 @@ class LiteSpeed_Cache_Control
241
public static function set_cacheable()
242
{
243
self::$_control |= self::BM_CACHEABLE ;
244
- LiteSpeed_Cache_Log::debug( 'X Cache_control init on' ) ;
245
}
246
247
/**
@@ -257,7 +257,7 @@ class LiteSpeed_Cache_Control
257
if ( $reason ) {
258
$reason = "( $reason )" ;
259
}
260
- LiteSpeed_Cache_Log::debug( 'X Cache_control -> no Cache ' . $reason, 2 ) ;
261
}
262
263
/**
@@ -298,7 +298,7 @@ class LiteSpeed_Cache_Control
298
{
299
if ( is_numeric($ttl) ) {
300
self::$_custom_ttl = $ttl ;
301
- LiteSpeed_Cache_Log::debug('X Cache_control TTL -> ' . $ttl) ;
302
}
303
}
304
@@ -328,7 +328,7 @@ class LiteSpeed_Cache_Control
328
if ( $ttl < 0 ) {
329
$ttl += 86400 ;// add one day
330
}
331
- LiteSpeed_Cache_Log::debug( 'X Cache_control TTL is limited to ' . $ttl ) ;
332
return $ttl ;
333
}
334
}
@@ -374,12 +374,30 @@ class LiteSpeed_Cache_Control
374
public static function check_redirect( $location, $status )
375
{
376
if ( ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ) { // dont check $status == '301' anymore
377
- LiteSpeed_Cache_Log::debug( "301 from " . $_SERVER[ 'SCRIPT_URI' ] ) ;
378
- LiteSpeed_Cache_Log::debug( "301 to $location" ) ;
379
- if ( parse_url( $_SERVER[ 'SCRIPT_URI' ], PHP_URL_PATH ) == parse_url( $location, PHP_URL_PATH ) ) {
380
self::set_nocache( '301 to same url' ) ;
381
}
382
}
383
return $location ;
384
}
385
@@ -433,7 +451,7 @@ class LiteSpeed_Cache_Control
433
// if is not cacheable, terminate check
434
// Even no need to run 3rd party hook
435
if ( ! self::is_cacheable() ) {
436
- LiteSpeed_Cache_Log::debug( 'not cacheable before ctrl finalize' ) ;
437
return ;
438
}
439
@@ -458,7 +476,7 @@ class LiteSpeed_Cache_Control
458
459
// if is not cacheable, terminate check
460
if ( ! self::is_cacheable() ) {
461
- LiteSpeed_Cache_Log::debug( 'not cacheable after api_control' ) ;
462
return ;
463
}
464
@@ -617,7 +635,7 @@ class LiteSpeed_Cache_Control
617
*/
618
private function _no_cache_for( $reason )
619
{
620
- LiteSpeed_Cache_Log::debug('X Cache_control off - ' . $reason) ;
621
return false ;
622
}
623
101
return ;
102
}
103
self::$_control |= self::BM_NO_VARY ;
104
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> no-vary', 3 ) ;
105
}
106
107
/**
127
return ;
128
}
129
self::$_control |= self::BM_STALE ;
130
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control -> stale') ;
131
}
132
133
/**
158
if ( $reason ) {
159
$reason = "( $reason )" ;
160
}
161
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> shared ' . $reason ) ;
162
}
163
164
/**
188
if ( $reason ) {
189
$reason = "( $reason )" ;
190
}
191
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> public forced ' . $reason ) ;
192
}
193
194
/**
218
if ( $reason ) {
219
$reason = "( $reason )" ;
220
}
221
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> private ' . $reason ) ;
222
}
223
224
/**
241
public static function set_cacheable()
242
{
243
self::$_control |= self::BM_CACHEABLE ;
244
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control init on' ) ;
245
}
246
247
/**
257
if ( $reason ) {
258
$reason = "( $reason )" ;
259
}
260
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control -> no Cache ' . $reason, 2 ) ;
261
}
262
263
/**
298
{
299
if ( is_numeric($ttl) ) {
300
self::$_custom_ttl = $ttl ;
301
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control TTL -> ' . $ttl) ;
302
}
303
}
304
328
if ( $ttl < 0 ) {
329
$ttl += 86400 ;// add one day
330
}
331
+ LiteSpeed_Cache_Log::debug( '[Ctrl] X Cache_control TTL is limited to ' . $ttl ) ;
332
return $ttl ;
333
}
334
}
374
public static function check_redirect( $location, $status )
375
{
376
if ( ! empty( $_SERVER[ 'SCRIPT_URI' ] ) ) { // dont check $status == '301' anymore
377
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 from " . $_SERVER[ 'SCRIPT_URI' ] ) ;
378
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 to $location" ) ;
379
+
380
+ $to_check = array(
381
+ PHP_URL_SCHEME,
382
+ PHP_URL_HOST,
383
+ PHP_URL_PATH,
384
+ ) ;
385
+
386
+ $is_same_redirect = true ;
387
+
388
+ foreach ( $to_check as $v ) {
389
+ if ( parse_url( $_SERVER[ 'SCRIPT_URI' ], $v ) != parse_url( $location, $v ) ) {
390
+ $is_same_redirect = false ;
391
+ LiteSpeed_Cache_Log::debug( "[Ctrl] 301 different redirection" ) ;
392
+ break ;
393
+ }
394
+ }
395
+
396
+ if ( $is_same_redirect ) {
397
self::set_nocache( '301 to same url' ) ;
398
}
399
}
400
+
401
return $location ;
402
}
403
451
// if is not cacheable, terminate check
452
// Even no need to run 3rd party hook
453
if ( ! self::is_cacheable() ) {
454
+ LiteSpeed_Cache_Log::debug( '[Ctrl] not cacheable before ctrl finalize' ) ;
455
return ;
456
}
457
476
477
// if is not cacheable, terminate check
478
if ( ! self::is_cacheable() ) {
479
+ LiteSpeed_Cache_Log::debug( '[Ctrl] not cacheable after api_control' ) ;
480
return ;
481
}
482
635
*/
636
private function _no_cache_for( $reason )
637
{
638
+ LiteSpeed_Cache_Log::debug('[Ctrl] X Cache_control off - ' . $reason) ;
639
return false ;
640
}
641
includes/litespeed-cache-gui.class.php CHANGED
@@ -372,11 +372,19 @@ class LiteSpeed_Cache_GUI
372
$wp_admin_bar->add_menu( array(
373
'parent' => 'litespeed-menu',
374
'id' => 'litespeed-purge-all',
375
- 'title' => __( 'LiteSpeed Cache Purge All', 'litespeed-cache' ),
376
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
377
'meta' => array( 'tabindex' => '0' ),
378
) );
379
380
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE ) ) {
381
$wp_admin_bar->add_menu( array(
382
'parent' => 'litespeed-menu',
372
$wp_admin_bar->add_menu( array(
373
'parent' => 'litespeed-menu',
374
'id' => 'litespeed-purge-all',
375
+ 'title' => __( 'LSCache Purge All', 'litespeed-cache' ),
376
'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_ALL ),
377
'meta' => array( 'tabindex' => '0' ),
378
) );
379
380
+ $wp_admin_bar->add_menu( array(
381
+ 'parent' => 'litespeed-menu',
382
+ 'id' => 'litespeed-purge-cssjs',
383
+ 'title' => __( 'Purge CSS/JS Cache', 'litespeed-cache' ),
384
+ 'href' => LiteSpeed_Cache_Utility::build_url( LiteSpeed_Cache::ACTION_PURGE_CSSJS ),
385
+ 'meta' => array( 'tabindex' => '0' ),
386
+ ) );
387
+
388
if ( LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_CDN_CLOUDFLARE ) ) {
389
$wp_admin_bar->add_menu( array(
390
'parent' => 'litespeed-menu',
includes/litespeed-cache-optimize.class.php CHANGED
@@ -34,6 +34,7 @@ class LiteSpeed_Cache_Optimize
34
private $cfg_exc_jquery ;
35
private $cfg_ggfonts_async ;
36
private $cfg_optm_max_size ;
37
38
private $dns_prefetch ;
39
@@ -69,6 +70,7 @@ class LiteSpeed_Cache_Optimize
69
$this->cfg_exc_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY ) ;
70
$this->cfg_ggfonts_async = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_ASYNC ) ;
71
$this->cfg_optm_max_size = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_MAX_SIZE ) * 1000000 ;
72
73
$this->_static_request_check() ;
74
@@ -181,7 +183,19 @@ class LiteSpeed_Cache_Optimize
181
{
182
// This request is for js/css_async.js
183
if ( ( $this->cfg_css_async || $this->cfg_ggfonts_async ) && strpos( $_SERVER[ 'REQUEST_URI' ], self::CSS_ASYNC_LIB ) !== false ) {
184
- LiteSpeed_Cache_Log::debug( 'Optimizer start serving static file' ) ;
185
186
LiteSpeed_Cache_Control::set_cacheable() ;
187
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: css async js' ) ;
@@ -189,12 +203,10 @@ class LiteSpeed_Cache_Optimize
189
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
190
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_CSS_ASYNC' ) ;
191
192
- $file = LSCWP_DIR . 'js/css_async.min.js' ;
193
-
194
- header( 'Content-Length: ' . filesize( $file ) ) ;
195
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
196
197
- echo file_get_contents( $file ) ;
198
exit ;
199
}
200
@@ -212,70 +224,69 @@ class LiteSpeed_Cache_Optimize
212
return ;
213
}
214
215
- LiteSpeed_Cache_Log::debug( 'Optimizer start minifying file' ) ;
216
217
// Proceed css/js file generation
218
define( 'LITESPEED_MIN_FILE', true ) ;
219
220
- $file_type = substr( $match[ 1 ], strrpos( $match[ 1 ], '.' ) + 1 ) ;
221
-
222
- $ttl = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ) ;
223
224
- // Load file from file based cache if not enabled lscache
225
- if ( ! defined( 'LITESPEED_ON' ) ) {
226
- LiteSpeed_Cache_Log::debug( '[Optimize] Not enabled lscache, using file based cache' ) ;
227
228
- $static_file = LSCWP_CONTENT_DIR . '/cache/' . $file_type . '/' . $match[ 1 ] ;
229
- if ( file_exists( $static_file ) && time() - filemtime( $static_file ) <= $ttl ) {
230
- $content = Litespeed_File::read( $static_file ) ;
231
232
- // Output header first
233
- $headers = array() ;
234
- $headers[ 'Content-Length' ] = strlen( $content ) ;
235
236
- if ( $file_type === 'css' ) {
237
- $headers[ 'Content-Type' ] = 'text/css; charset=utf-8' ;
238
- }
239
- else {
240
- $headers[ 'Content-Type' ] = 'application/x-javascript' ;
241
- }
242
243
- foreach ( $headers as $k => $v ) {
244
- header( $k . ': ' . $v ) ;
245
- LiteSpeed_Cache_Log::debug( '[Optimize] HEADER ' . $k . ': ' . $v ) ;
246
- }
247
248
- echo $content ;
249
- exit ;
250
- }
251
}
252
-
253
- $concat_only = ! ( $file_type === 'css' ? $this->cfg_css_minify : $this->cfg_js_minify ) ;
254
-
255
- $content = LiteSpeed_Cache_Optimizer::get_instance()->serve( $match[ 1 ], $concat_only ) ;
256
-
257
- if ( ! $content ) {
258
- LiteSpeed_Cache_Control::set_nocache( 'Empty content from optimizer' ) ;
259
- exit ;
260
}
261
262
- // Save to file if not enabled lscache
263
- if ( ! defined( 'LITESPEED_ON' ) ) {
264
- LiteSpeed_Cache_Log::debug( '[Optimize] Saved cache to file [path] ' . $static_file ) ;
265
-
266
- Litespeed_File::save( $static_file, $content, true ) ;
267
- }
268
269
LiteSpeed_Cache_Control::set_cacheable() ;
270
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: min file ' . $match[ 1 ] ) ;
271
LiteSpeed_Cache_Control::set_no_vary() ;
272
- LiteSpeed_Cache_Control::set_custom_ttl( $ttl ) ;
273
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN ) ;
274
275
echo $content ;
276
exit ;
277
}
278
279
/**
280
* Delete file-based cache folder
281
*
@@ -349,7 +360,7 @@ class LiteSpeed_Cache_Optimize
349
}
350
351
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
352
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: Not frontend HTML type' ) ;
353
return $content ;
354
}
355
@@ -358,19 +369,19 @@ class LiteSpeed_Cache_Optimize
358
if ( ! empty( $excludes ) ) {
359
$result = LiteSpeed_Cache_Utility::str_hit_array( esc_url( $_SERVER[ 'REQUEST_URI' ] ), explode( "\n", $excludes ) ) ;
360
if ( $result ) {
361
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: hit URI Excludes setting: ' . $result ) ;
362
return $content ;
363
}
364
}
365
366
// Check if is exclude optm roles ( Need to set Vary too )
367
if ( $result = LiteSpeed_Cache_Config::get_instance()->in_exclude_optimization_roles() ) {
368
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: hit Role Excludes setting: ' . $result ) ;
369
return $content ;
370
}
371
372
373
- LiteSpeed_Cache_Log::debug( 'Optimizer start' ) ;
374
375
$instance = self::get_instance() ;
376
$instance->content = $content ;
@@ -388,7 +399,7 @@ class LiteSpeed_Cache_Optimize
388
private function _optimize()
389
{
390
if ( ! $this->_can_optm() ) {
391
- LiteSpeed_Cache_Log::debug( 'Optimizer bypass: admin/feed/preview' ) ;
392
return ;
393
}
394
@@ -492,7 +503,7 @@ class LiteSpeed_Cache_Optimize
492
continue ;
493
}
494
495
- LiteSpeed_Cache_Log::debug( 'Optm: google fonts async loading: ' . $src_list[ $k ] ) ;
496
}
497
// async html
498
$html_list_async = $this->_async_css_list( $html_list ) ;
@@ -662,7 +673,7 @@ class LiteSpeed_Cache_Optimize
662
$this->content .= "\n" . '<!-- Page optimized by LiteSpeed Cache on '.date('Y-m-d H:i:s').' -->' ;
663
664
} catch ( ErrorException $e ) {
665
- LiteSpeed_Cache_Log::debug( 'Error when optimizing HTML: ' . $e->getMessage() ) ;
666
error_log( 'LiteSpeed Optimizer optimizing HTML Error: ' . $e->getMessage() ) ;
667
// If failed to minify HTML, restore original content
668
$this->content = $ori ;
@@ -759,7 +770,7 @@ class LiteSpeed_Cache_Optimize
759
}
760
}
761
if ( count( $src_arr ) > 1 ) {
762
- LiteSpeed_Cache_Log::debug( 'Optimizer: separate ' . $file_type . ' to ' . count( $src_arr ) ) ;
763
}
764
765
// group build
@@ -831,7 +842,7 @@ class LiteSpeed_Cache_Optimize
831
832
// Analyse links
833
foreach ( $src_list as $key => $src ) {
834
- LiteSpeed_Cache_Log::debug2( 'Optm: ' . $src ) ;
835
836
/**
837
* Excluded links won't be done any optm
@@ -839,14 +850,14 @@ class LiteSpeed_Cache_Optimize
839
*/
840
// if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $src, $excludes ) ) {
841
// $ignored_html[] = $html_list[ $key ] ;
842
- // LiteSpeed_Cache_Log::debug2( 'Optm: Abort excludes: ' . $exclude ) ;
843
// continue ;
844
// }
845
846
// Check if has no-optimize attr
847
if ( strpos( $html_list[ $key ], 'data-no-optimize' ) !== false ) {
848
$ignored_html[] = $html_list[ $key ] ;
849
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort excludes: attr data-no-optimize' ) ;
850
continue ;
851
}
852
@@ -854,7 +865,7 @@ class LiteSpeed_Cache_Optimize
854
$url_parsed = parse_url( $src ) ;
855
if ( ! $file_info = LiteSpeed_Cache_Utility::is_internal_file( $src ) ) {
856
$ignored_html[ $src ] = $html_list[ $key ] ;
857
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort external/non-exist' ) ;
858
continue ;
859
}
860
@@ -865,7 +876,7 @@ class LiteSpeed_Cache_Optimize
865
*/
866
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
867
$ignored_html[ $src ] = $html_list[ $key ] ;
868
- LiteSpeed_Cache_Log::debug2( 'Optm: Abort jQuery by setting' ) ;
869
870
// Add to HTTP2 as its ignored but still internal src
871
$this->append_http2( $src, 'js' ) ;
@@ -896,6 +907,7 @@ class LiteSpeed_Cache_Optimize
896
if ( ! is_array( $src ) ) {
897
$src = array( $src ) ;
898
}
899
$src = array_values( $src ) ;
900
901
$hash = md5( serialize( $src ) ) ;
@@ -918,6 +930,21 @@ class LiteSpeed_Cache_Optimize
918
LiteSpeed_Cache_Data::optm_save_src( $short . '.' . $file_type, $src ) ;
919
}
920
921
$file_to_save = self::DIR_MIN . '/' . $filename . '.' . $file_type ;
922
923
return LiteSpeed_Cache_Utility::get_permalink_url( $file_to_save ) ;
@@ -967,7 +994,7 @@ class LiteSpeed_Cache_Optimize
967
}
968
// todo @v2.0: allow defer even exclude from optm
969
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'src' ], $excludes ) ) {
970
- LiteSpeed_Cache_Log::debug2( 'Optm: _parse_js bypassed exclude ' . $exclude ) ;
971
continue ;
972
}
973
@@ -1027,13 +1054,13 @@ class LiteSpeed_Cache_Optimize
1027
}
1028
1029
if ( $excludes && $exclude = LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $excludes ) ) {
1030
- LiteSpeed_Cache_Log::debug2( 'Optm: _handle_css bypassed exclude ' . $exclude ) ;
1031
continue ;
1032
}
1033
1034
// Check if need to remove this css
1035
if ( $this->css_to_be_removed && LiteSpeed_Cache_Utility::str_hit_array( $attrs[ 'href' ], $this->css_to_be_removed ) ) {
1036
- LiteSpeed_Cache_Log::debug( 'Optm: rm css snippet ' . $attrs[ 'href' ] ) ;
1037
// Delete this css snippet from orig html
1038
$this->content = str_replace( $match[ 0 ], '', $this->content ) ;
1039
continue ;
@@ -1063,12 +1090,12 @@ class LiteSpeed_Cache_Optimize
1063
{
1064
foreach ( $html_list as $k => $ori ) {
1065
if ( strpos( $ori, 'data-asynced' ) !== false ) {
1066
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr data-asynced exist' ) ;
1067
continue ;
1068
}
1069
1070
if ( strpos( $ori, 'data-no-async' ) !== false ) {
1071
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr api data-no-async' ) ;
1072
continue ;
1073
}
1074
@@ -1098,11 +1125,11 @@ class LiteSpeed_Cache_Optimize
1098
continue ;
1099
}
1100
if ( strpos( $v, 'data-deferred' ) !== false ) {
1101
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr data-deferred exist' ) ;
1102
continue ;
1103
}
1104
if ( strpos( $v, 'data-no-defer' ) !== false ) {
1105
- LiteSpeed_Cache_Log::debug2( 'Optm bypass: attr api data-no-defer' ) ;
1106
continue ;
1107
}
1108
@@ -1114,14 +1141,14 @@ class LiteSpeed_Cache_Optimize
1114
// parse js src
1115
preg_match( '#<script \s*([^>]+)>#isU', $v, $matches ) ;
1116
if ( empty( $matches[ 1 ] ) ) {
1117
- LiteSpeed_Cache_Log::debug( 'Optm: js defer parse html failed: ' . $v ) ;
1118
continue ;
1119
}
1120
1121
$attrs = LiteSpeed_Cache_Utility::parse_attr( $matches[ 1 ] ) ;
1122
1123
if ( empty( $attrs[ 'src' ] ) ) {
1124
- LiteSpeed_Cache_Log::debug( 'Optm: js defer parse src failed: ' . $matches[ 1 ] ) ;
1125
continue ;
1126
}
1127
@@ -1133,7 +1160,7 @@ class LiteSpeed_Cache_Optimize
1133
* @since 1.5
1134
*/
1135
if ( $this->cfg_js_defer_exc && LiteSpeed_Cache_Utility::str_hit_array( $src, $this->cfg_js_defer_exc ) ) {
1136
- LiteSpeed_Cache_Log::debug( 'Optm: js defer exclude ' . $src ) ;
1137
continue ;
1138
}
1139
@@ -1142,7 +1169,7 @@ class LiteSpeed_Cache_Optimize
1142
* @since 1.5
1143
*/
1144
if ( $this->cfg_exc_jquery && $this->_is_jquery( $src ) ) {
1145
- LiteSpeed_Cache_Log::debug2( 'Optm: js defer Abort jQuery by setting' ) ;
1146
continue ;
1147
}
1148
34
private $cfg_exc_jquery ;
35
private $cfg_ggfonts_async ;
36
private $cfg_optm_max_size ;
37
+ private $cfg_ttl ;
38
39
private $dns_prefetch ;
40
70
$this->cfg_exc_jquery = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_EXC_JQUERY ) ;
71
$this->cfg_ggfonts_async = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_GGFONTS_ASYNC ) ;
72
$this->cfg_optm_max_size = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTM_MAX_SIZE ) * 1000000 ;
73
+ $this->cfg_ttl = LiteSpeed_Cache::config( LiteSpeed_Cache_Config::OPID_OPTIMIZE_TTL ) ;
74
75
$this->_static_request_check() ;
76
183
{
184
// This request is for js/css_async.js
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
+
194
+ // Save to cache folder to enable directly usage by .htacess
195
+ if ( ! file_exists( $static_file ) ) {
196
+ Litespeed_File::save( $static_file, $content, true ) ;
197
+ LiteSpeed_Cache_Log::debug( '[Optm] save css_async lib to ' . $static_file ) ;
198
+ }
199
200
LiteSpeed_Cache_Control::set_cacheable() ;
201
LiteSpeed_Cache_Control::set_public_forced( 'OPTM: css async js' ) ;
203
LiteSpeed_Cache_Control::set_custom_ttl( 8640000 ) ;
204
LiteSpeed_Cache_Tag::add( LiteSpeed_Cache_Tag::TYPE_MIN . '_CSS_ASYNC' ) ;
205
206
+ header( 'Content-Length: ' . strlen( $content ) ) ;
207
header( 'Content-Type: application/x-javascript; charset=utf-8' ) ;
208
209
+ echo $content ;
210
exit ;
211
}
212
224
return ;
225
}
226
227
+ LiteSpeed_Cache_Log::debug( '[Optm] start minifying file' ) ;
228
229
// Proceed css/js file generation
230
define( 'LITESPEED_MIN_FILE', true ) ;
231
232
+ $file_type = $match[ 2 ] ;
233