Version Description
- Higher accuracy in detecting the source map for CSS & JS files in order to update it if the caching file is created; Make sure no caching file is created if there's no change already made to the JS content (e.g. minify), otherwise, it doesn't make sense to only change the source map
- Delete an option related to the plugin (from {wp_}options) instead of updating it with an empty value
- Do not trigger the plugin when Zion Page Builder from Kallyas theme is used to avoid using extra resources or print any assets below the page when "Manage in the front-end" is enabled, thus, cluttering the page
- Fix: Sometimes, due to multiple query strings the optimized asset URLs weren't replacing the original asset URLs correctly (e.g. /?version=value&ver=1.2)
- Fix (CSS Minify): Do not update "0px" to "0" from a global declared variable (e.g. ":root { --some-var: 0px; }" should not have "px" removed)
- Fix: Avoid preg_match() errors coming from any RegEx from the following option: "Do not combine the (CSS|JavaScript) files matching the patterns below (one per line)"
- Fix: If WordPress version is below 5, an error is generated when print_translations() is triggered because the method does not exists within wp_scripts()
- Fix: Prevent combined CSS files from generating from just one file (useless) when the array is filled twice by mistake with the same file path
Download this release
Release Info
Developer | gabelivan |
Plugin | Asset CleanUp: Page Speed Booster |
Version | 1.3.7.5 |
Comparing to | |
See all releases |
Code changes from version 1.3.7.4 to 1.3.7.5
- classes/Main.php +17 -7
- classes/Misc.php +42 -4
- classes/OptimiseAssets/CombineCss.php +42 -25
- classes/OptimiseAssets/CombineJs.php +38 -19
- classes/OptimiseAssets/MinifyCss.php +25 -0
- classes/OptimiseAssets/OptimizeCommon.php +23 -3
- classes/OptimiseAssets/OptimizeCss.php +26 -10
- classes/OptimiseAssets/OptimizeJs.php +35 -14
- readme.txt +11 -1
- wpacu.php +2 -2
classes/Main.php
CHANGED
@@ -959,7 +959,7 @@ SQL;
|
|
959 |
$stylesSpecialCases = json_decode($jsonStylesSpecialCases, ARRAY_A);
|
960 |
|
961 |
if (Misc::jsonLastError() === JSON_ERROR_NONE && ! empty($stylesSpecialCases)) {
|
962 |
-
foreach ($stylesSpecialCases as $
|
963 |
$styleLocalSrc = Misc::getLocalSrc($styleSrc);
|
964 |
$styleRelSrc = isset($styleLocalSrc['rel_src']) ? $styleLocalSrc['rel_src'] : $styleSrc;
|
965 |
$htmlSource = CleanUp::cleanLinkTagFromHtmlSource($styleRelSrc, $htmlSource);
|
@@ -1208,19 +1208,19 @@ SQL;
|
|
1208 |
|
1209 |
$assetHandles = array();
|
1210 |
|
1211 |
-
if (strpos($unloadAsset, ',') === false) {
|
1212 |
-
if (strpos($unloadAsset, '[ignore-deps]')
|
1213 |
$unloadAsset = str_replace('[ignore-deps]', '', $unloadAsset);
|
1214 |
$this->ignoreChildrenHandlesOnTheFly[$assetType][] = $unloadAsset;
|
1215 |
}
|
1216 |
|
1217 |
$assetHandles[] = $unloadAsset;
|
1218 |
-
} else {
|
1219 |
foreach (explode(',', $unloadAsset) as $unloadAsset) {
|
1220 |
$unloadAsset = trim($unloadAsset);
|
1221 |
|
1222 |
if ($unloadAsset) {
|
1223 |
-
if (strpos($unloadAsset, '[ignore-deps]')
|
1224 |
$unloadAsset = str_replace('[ignore-deps]', '', $unloadAsset);
|
1225 |
$this->ignoreChildrenHandlesOnTheFly[$assetType][] = $unloadAsset;
|
1226 |
}
|
@@ -2557,7 +2557,9 @@ SQL;
|
|
2557 |
|
2558 |
$isInAdminPageViaAjax = (is_admin() && defined('DOING_AJAX') && DOING_AJAX);
|
2559 |
|
2560 |
-
if (empty($this->assetsRemoved)) {
|
|
|
|
|
2561 |
// For Home Page (latest blog posts)
|
2562 |
if ( $postId < 1 && ( $isInAdminPageViaAjax || Misc::isHomePage() ) ) {
|
2563 |
$this->assetsRemoved = get_option( WPACU_PLUGIN_ID . '_front_page_no_load' );
|
@@ -2567,13 +2569,21 @@ SQL;
|
|
2567 |
|
2568 |
@json_decode( $this->assetsRemoved );
|
2569 |
|
2570 |
-
if ( ! ( Misc::jsonLastError() === JSON_ERROR_NONE ) || empty( $this->assetsRemoved ) ) {
|
2571 |
// Reset value to a JSON formatted one
|
2572 |
$this->assetsRemoved = json_encode( array( 'styles' => array(), 'scripts' => array() ) );
|
2573 |
}
|
2574 |
|
2575 |
$assetsRemovedDecoded = json_decode( $this->assetsRemoved, ARRAY_A );
|
2576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2577 |
/* [START] Unload CSS/JS on page request for debugging purposes */
|
2578 |
$assetsUnloadedOnTheFly = array( 'styles' => array(), 'scripts' => array() );
|
2579 |
|
959 |
$stylesSpecialCases = json_decode($jsonStylesSpecialCases, ARRAY_A);
|
960 |
|
961 |
if (Misc::jsonLastError() === JSON_ERROR_NONE && ! empty($stylesSpecialCases)) {
|
962 |
+
foreach ($stylesSpecialCases as $styleSrc) {
|
963 |
$styleLocalSrc = Misc::getLocalSrc($styleSrc);
|
964 |
$styleRelSrc = isset($styleLocalSrc['rel_src']) ? $styleLocalSrc['rel_src'] : $styleSrc;
|
965 |
$htmlSource = CleanUp::cleanLinkTagFromHtmlSource($styleRelSrc, $htmlSource);
|
1208 |
|
1209 |
$assetHandles = array();
|
1210 |
|
1211 |
+
if (strpos($unloadAsset, ',') === false) { // No comma, just one asset targeted
|
1212 |
+
if (strpos($unloadAsset, '[ignore-deps]') !== false) {
|
1213 |
$unloadAsset = str_replace('[ignore-deps]', '', $unloadAsset);
|
1214 |
$this->ignoreChildrenHandlesOnTheFly[$assetType][] = $unloadAsset;
|
1215 |
}
|
1216 |
|
1217 |
$assetHandles[] = $unloadAsset;
|
1218 |
+
} else { // There are commas, multiple assets targeted
|
1219 |
foreach (explode(',', $unloadAsset) as $unloadAsset) {
|
1220 |
$unloadAsset = trim($unloadAsset);
|
1221 |
|
1222 |
if ($unloadAsset) {
|
1223 |
+
if (strpos($unloadAsset, '[ignore-deps]') !== false) {
|
1224 |
$unloadAsset = str_replace('[ignore-deps]', '', $unloadAsset);
|
1225 |
$this->ignoreChildrenHandlesOnTheFly[$assetType][] = $unloadAsset;
|
1226 |
}
|
2557 |
|
2558 |
$isInAdminPageViaAjax = (is_admin() && defined('DOING_AJAX') && DOING_AJAX);
|
2559 |
|
2560 |
+
if ( empty($this->assetsRemoved) ) {
|
2561 |
+
$this->assetsRemoved = json_encode( array( 'styles' => array(), 'scripts' => array() ) );
|
2562 |
+
|
2563 |
// For Home Page (latest blog posts)
|
2564 |
if ( $postId < 1 && ( $isInAdminPageViaAjax || Misc::isHomePage() ) ) {
|
2565 |
$this->assetsRemoved = get_option( WPACU_PLUGIN_ID . '_front_page_no_load' );
|
2569 |
|
2570 |
@json_decode( $this->assetsRemoved );
|
2571 |
|
2572 |
+
if ( ! ( Misc::jsonLastError() === JSON_ERROR_NONE ) || empty( $this->assetsRemoved ) || $this->assetsRemoved === '[]' ) {
|
2573 |
// Reset value to a JSON formatted one
|
2574 |
$this->assetsRemoved = json_encode( array( 'styles' => array(), 'scripts' => array() ) );
|
2575 |
}
|
2576 |
|
2577 |
$assetsRemovedDecoded = json_decode( $this->assetsRemoved, ARRAY_A );
|
2578 |
|
2579 |
+
if (! isset($assetsRemovedDecoded['styles'])) {
|
2580 |
+
$assetsRemovedDecoded['styles'] = array();
|
2581 |
+
}
|
2582 |
+
|
2583 |
+
if (! isset($assetsRemovedDecoded['scripts'])) {
|
2584 |
+
$assetsRemovedDecoded['scripts'] = array();
|
2585 |
+
}
|
2586 |
+
|
2587 |
/* [START] Unload CSS/JS on page request for debugging purposes */
|
2588 |
$assetsUnloadedOnTheFly = array( 'styles' => array(), 'scripts' => array() );
|
2589 |
|
classes/Misc.php
CHANGED
@@ -646,6 +646,12 @@ HTML;
|
|
646 |
return;
|
647 |
}
|
648 |
|
|
|
|
|
|
|
|
|
|
|
|
|
649 |
// Value is in the database already | Update it
|
650 |
update_option($optionName, $optionValue, $autoload);
|
651 |
}
|
@@ -760,7 +766,7 @@ SQL;
|
|
760 |
} elseif (in_array($bulkUnloadedType, array('post_type', 'taxonomy'))) {
|
761 |
foreach (array('styles', 'scripts') as $assetType) {
|
762 |
if ( isset( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] ) && ! empty( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] ) ) {
|
763 |
-
foreach ( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] as $
|
764 |
$unloadedTotalAssets += count( $objectValues );
|
765 |
}
|
766 |
}
|
@@ -1279,6 +1285,40 @@ SQL;
|
|
1279 |
return $array;
|
1280 |
}
|
1281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1282 |
/**
|
1283 |
* @param $name
|
1284 |
* @param $action
|
@@ -1346,7 +1386,7 @@ SQL;
|
|
1346 |
$wpacuTimingFormatMs = $timingValues['ms'];
|
1347 |
$wpacuTimingFormatS = $timingValues['s'];
|
1348 |
|
1349 |
-
|
1350 |
array(
|
1351 |
'{' . $wpacuCacheKey . '}',
|
1352 |
'{' . $wpacuCacheKey . '_sec}'
|
@@ -1356,7 +1396,5 @@ SQL;
|
|
1356 |
$wpacuTimingFormatS . 's',
|
1357 |
), // clean it up
|
1358 |
$htmlSource );
|
1359 |
-
|
1360 |
-
return $htmlSource;
|
1361 |
}
|
1362 |
}
|
646 |
return;
|
647 |
}
|
648 |
|
649 |
+
// Empty array encoded into JSON; No point in keeping the option in the database
|
650 |
+
if ($optionValue === '[]') {
|
651 |
+
delete_option($optionName);
|
652 |
+
return;
|
653 |
+
}
|
654 |
+
|
655 |
// Value is in the database already | Update it
|
656 |
update_option($optionName, $optionValue, $autoload);
|
657 |
}
|
766 |
} elseif (in_array($bulkUnloadedType, array('post_type', 'taxonomy'))) {
|
767 |
foreach (array('styles', 'scripts') as $assetType) {
|
768 |
if ( isset( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] ) && ! empty( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] ) ) {
|
769 |
+
foreach ( $bulkUnloadArray[$assetType][ $bulkUnloadedType ] as $objectValues ) {
|
770 |
$unloadedTotalAssets += count( $objectValues );
|
771 |
}
|
772 |
}
|
1285 |
return $array;
|
1286 |
}
|
1287 |
|
1288 |
+
/**
|
1289 |
+
* Single value (no multiple RegExes)
|
1290 |
+
*
|
1291 |
+
* @param $regexValue
|
1292 |
+
*
|
1293 |
+
* @return mixed|string
|
1294 |
+
*/
|
1295 |
+
public static function purifyRegexValue($regexValue)
|
1296 |
+
{
|
1297 |
+
try {
|
1298 |
+
if ( class_exists( '\CleanRegex\Pattern' )
|
1299 |
+
&& class_exists( '\SafeRegex\preg' )
|
1300 |
+
&& method_exists( '\CleanRegex\Pattern', 'delimitered' )
|
1301 |
+
&& method_exists( '\SafeRegex\preg', 'match' ) ) {
|
1302 |
+
$cleanRegexPattern = new \CleanRegex\Pattern( $regexValue );
|
1303 |
+
$delimiteredValue = $cleanRegexPattern->delimitered(); // auto-correct it if there's no delimiter
|
1304 |
+
|
1305 |
+
if ( $delimiteredValue ) {
|
1306 |
+
// Tip: https://stackoverflow.com/questions/4440626/how-can-i-validate-regex
|
1307 |
+
// Validate it and if it doesn't match, do not add it to the list
|
1308 |
+
@preg_match( $delimiteredValue, null );
|
1309 |
+
|
1310 |
+
if ( preg_last_error() !== PREG_NO_ERROR ) {
|
1311 |
+
return $regexValue;
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
}
|
1315 |
+
$regexValue = trim($regexValue);
|
1316 |
+
}
|
1317 |
+
} catch( \Exception $e) {} // if T-Regx library didn't load as it should, the textarea value will be kept as it is
|
1318 |
+
|
1319 |
+
return $regexValue;
|
1320 |
+
}
|
1321 |
+
|
1322 |
/**
|
1323 |
* @param $name
|
1324 |
* @param $action
|
1386 |
$wpacuTimingFormatMs = $timingValues['ms'];
|
1387 |
$wpacuTimingFormatS = $timingValues['s'];
|
1388 |
|
1389 |
+
return str_replace(
|
1390 |
array(
|
1391 |
'{' . $wpacuCacheKey . '}',
|
1392 |
'{' . $wpacuCacheKey . '_sec}'
|
1396 |
$wpacuTimingFormatS . 's',
|
1397 |
), // clean it up
|
1398 |
$htmlSource );
|
|
|
|
|
1399 |
}
|
1400 |
}
|
classes/OptimiseAssets/CombineCss.php
CHANGED
@@ -37,19 +37,23 @@ class CombineCss
|
|
37 |
global $wp_styles;
|
38 |
$wpacuRegisteredStyles = $wp_styles->registered;
|
39 |
|
40 |
-
|
41 |
-
// This will avoid parsing the HTML DOM and determine the combined URI paths for all the CSS files
|
42 |
-
$storageJsonContents = OptimizeCommon::getAssetCachedData(self::$jsonStorageFile, OptimizeCss::getRelPathCssCacheDir(), 'css');
|
43 |
-
|
44 |
-
// $uriToFinalCssFile will always be relative ONLY within WP_CONTENT_DIR . self::getRelPathCssCacheDir()
|
45 |
-
// which is usually "wp-content/cache/asset-cleanup/css/"
|
46 |
-
|
47 |
$skipCache = false; // default
|
48 |
|
49 |
if (isset($_GET['wpacu_no_cache']) || (defined('WPACU_NO_CACHE') && WPACU_NO_CACHE === true)) {
|
50 |
$skipCache = true;
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
if ( $skipCache || empty($storageJsonContents) ) {
|
54 |
$storageJsonContentsToSave = array();
|
55 |
|
@@ -84,6 +88,15 @@ class CombineCss
|
|
84 |
if (isset($linkAttributes['rel'], $linkAttributes['href']) && $linkAttributes['href']) {
|
85 |
$href = (string) $linkAttributes['href'];
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
// Separate each combined group by the "media" attribute; e.g. we don't want "all" and "print" mixed
|
88 |
$mediaValue = (array_key_exists('media', $linkAttributes) && $linkAttributes['media']) ? $linkAttributes['media'] : 'all';
|
89 |
|
@@ -95,15 +108,6 @@ class CombineCss
|
|
95 |
$mediaValue = 'wpacu_preload_basic_' . $mediaValue;
|
96 |
}
|
97 |
|
98 |
-
// Check if the CSS file has any 'data-wpacu-skip' attribute; if it does, do not alter it
|
99 |
-
if (isset($linkAttributes['data-wpacu-skip'])) {
|
100 |
-
continue;
|
101 |
-
}
|
102 |
-
|
103 |
-
if (self::skipCombine($linkAttributes['href'])) {
|
104 |
-
continue;
|
105 |
-
}
|
106 |
-
|
107 |
// Make the right reference for later use
|
108 |
if ($linkAttributes['rel'] === 'preload') {
|
109 |
if (isset($linkAttributes['data-wpacu-preload-css-basic'])) {
|
@@ -133,9 +137,20 @@ class CombineCss
|
|
133 |
$styleExtra = $wpacuRegisteredStyles[$linkAttributes['data-wpacu-style-handle']]->extra;
|
134 |
}
|
135 |
|
136 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
$localAssetsPathsGroup[$mediaValue][$href] = $localAssetPath;
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
139 |
$localAssetsExtraGroup[$mediaValue][$href] = $styleExtra;
|
140 |
}
|
141 |
}
|
@@ -368,7 +383,7 @@ HTML;
|
|
368 |
public static function skipCombine($href)
|
369 |
{
|
370 |
$regExps = array(
|
371 |
-
'#/wp-content/bs-booster-cache/#'
|
372 |
);
|
373 |
|
374 |
if (Main::instance()->settings['combine_loaded_css_exceptions'] !== '') {
|
@@ -377,11 +392,11 @@ HTML;
|
|
377 |
if (strpos($loadedCssExceptionsPatterns, "\n")) {
|
378 |
// Multiple values (one per line)
|
379 |
foreach (explode("\n", $loadedCssExceptionsPatterns) as $loadedCssExceptionPattern) {
|
380 |
-
$regExps[] = trim($loadedCssExceptionPattern);
|
381 |
}
|
382 |
} else {
|
383 |
// Only one value?
|
384 |
-
$regExps[] = trim($loadedCssExceptionsPatterns);
|
385 |
}
|
386 |
}
|
387 |
|
@@ -391,7 +406,9 @@ HTML;
|
|
391 |
}
|
392 |
|
393 |
foreach ($regExps as $regExp) {
|
394 |
-
|
|
|
|
|
395 |
// Skip combination
|
396 |
return true;
|
397 |
}
|
@@ -428,11 +445,11 @@ HTML;
|
|
428 |
$pathToAssetDir = OptimizeCommon::getPathToAssetDir($assetHref);
|
429 |
|
430 |
// Does it have a source map? Strip it
|
431 |
-
if (strpos($cssContent, 'sourceMappingURL') !== false) {
|
432 |
-
$cssContent = OptimizeCommon::stripSourceMap($cssContent);
|
433 |
}
|
434 |
|
435 |
-
$finalCombinedCssContent .= '/*!
|
436 |
$finalCombinedCssContent .= OptimizeCss::maybeFixCssContent($cssContent, $pathToAssetDir . '/') . "\n";
|
437 |
|
438 |
$finalCombinedCssContent = self::appendToCombineCss($localAssetsExtra, $assetHref, $pathToAssetDir, $finalCombinedCssContent);
|
37 |
global $wp_styles;
|
38 |
$wpacuRegisteredStyles = $wp_styles->registered;
|
39 |
|
40 |
+
$storageJsonContents = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
$skipCache = false; // default
|
42 |
|
43 |
if (isset($_GET['wpacu_no_cache']) || (defined('WPACU_NO_CACHE') && WPACU_NO_CACHE === true)) {
|
44 |
$skipCache = true;
|
45 |
}
|
46 |
|
47 |
+
// If cache is not skipped, read the information from the cache as it's much faster
|
48 |
+
if (! $skipCache) {
|
49 |
+
// Speed up processing by getting the already existing final CSS file URI
|
50 |
+
// This will avoid parsing the HTML DOM and determine the combined URI paths for all the CSS files
|
51 |
+
$storageJsonContents = OptimizeCommon::getAssetCachedData( self::$jsonStorageFile, OptimizeCss::getRelPathCssCacheDir(), 'css' );
|
52 |
+
}
|
53 |
+
|
54 |
+
// $uriToFinalCssFile will always be relative ONLY within WP_CONTENT_DIR . self::getRelPathCssCacheDir()
|
55 |
+
// which is usually "wp-content/cache/asset-cleanup/css/"
|
56 |
+
|
57 |
if ( $skipCache || empty($storageJsonContents) ) {
|
58 |
$storageJsonContentsToSave = array();
|
59 |
|
88 |
if (isset($linkAttributes['rel'], $linkAttributes['href']) && $linkAttributes['href']) {
|
89 |
$href = (string) $linkAttributes['href'];
|
90 |
|
91 |
+
if (self::skipCombine($linkAttributes['href'])) {
|
92 |
+
continue;
|
93 |
+
}
|
94 |
+
|
95 |
+
// Check if the CSS file has any 'data-wpacu-skip' attribute; if it does, do not alter it
|
96 |
+
if (isset($linkAttributes['data-wpacu-skip']) || isset($scriptAttributes['data-wpacu-apply-media-query'])) {
|
97 |
+
continue;
|
98 |
+
}
|
99 |
+
|
100 |
// Separate each combined group by the "media" attribute; e.g. we don't want "all" and "print" mixed
|
101 |
$mediaValue = (array_key_exists('media', $linkAttributes) && $linkAttributes['media']) ? $linkAttributes['media'] : 'all';
|
102 |
|
108 |
$mediaValue = 'wpacu_preload_basic_' . $mediaValue;
|
109 |
}
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
// Make the right reference for later use
|
112 |
if ($linkAttributes['rel'] === 'preload') {
|
113 |
if (isset($linkAttributes['data-wpacu-preload-css-basic'])) {
|
137 |
$styleExtra = $wpacuRegisteredStyles[$linkAttributes['data-wpacu-style-handle']]->extra;
|
138 |
}
|
139 |
|
140 |
+
$sourceRelPath = OptimizeCommon::getSourceRelPath($href);
|
141 |
+
|
142 |
+
$alreadyAddedSourceRelPath = isset($combinedUriPathsGroup[$mediaValue]) && in_array($sourceRelPath, $combinedUriPathsGroup[$mediaValue]);
|
143 |
+
if (! $alreadyAddedSourceRelPath) {
|
144 |
+
$combinedUriPathsGroup[$mediaValue][] = $sourceRelPath;
|
145 |
+
}
|
146 |
+
|
147 |
$localAssetsPathsGroup[$mediaValue][$href] = $localAssetPath;
|
148 |
+
|
149 |
+
$alreadyAddedHref = isset($linkHrefsGroup[$mediaValue]) && in_array($href, $linkHrefsGroup[$mediaValue]);
|
150 |
+
if (! $alreadyAddedHref) {
|
151 |
+
$linkHrefsGroup[$mediaValue][] = $href;
|
152 |
+
}
|
153 |
+
|
154 |
$localAssetsExtraGroup[$mediaValue][$href] = $styleExtra;
|
155 |
}
|
156 |
}
|
383 |
public static function skipCombine($href)
|
384 |
{
|
385 |
$regExps = array(
|
386 |
+
'#/wp-content/bs-booster-cache/#'
|
387 |
);
|
388 |
|
389 |
if (Main::instance()->settings['combine_loaded_css_exceptions'] !== '') {
|
392 |
if (strpos($loadedCssExceptionsPatterns, "\n")) {
|
393 |
// Multiple values (one per line)
|
394 |
foreach (explode("\n", $loadedCssExceptionsPatterns) as $loadedCssExceptionPattern) {
|
395 |
+
$regExps[] = '#'.trim($loadedCssExceptionPattern).'#';
|
396 |
}
|
397 |
} else {
|
398 |
// Only one value?
|
399 |
+
$regExps[] = '#'.trim($loadedCssExceptionsPatterns).'#';
|
400 |
}
|
401 |
}
|
402 |
|
406 |
}
|
407 |
|
408 |
foreach ($regExps as $regExp) {
|
409 |
+
$regExp = Misc::purifyRegexValue($regExp);
|
410 |
+
|
411 |
+
if ( @preg_match( $regExp, $href ) || ( strpos($href, $regExp) !== false ) ) {
|
412 |
// Skip combination
|
413 |
return true;
|
414 |
}
|
445 |
$pathToAssetDir = OptimizeCommon::getPathToAssetDir($assetHref);
|
446 |
|
447 |
// Does it have a source map? Strip it
|
448 |
+
if (strpos($cssContent, '/*# sourceMappingURL=') !== false) {
|
449 |
+
$cssContent = OptimizeCommon::stripSourceMap($cssContent, 'css');
|
450 |
}
|
451 |
|
452 |
+
$finalCombinedCssContent .= '/*!'.str_replace(ABSPATH, '/', $localAssetsPath)."*/\n";
|
453 |
$finalCombinedCssContent .= OptimizeCss::maybeFixCssContent($cssContent, $pathToAssetDir . '/') . "\n";
|
454 |
|
455 |
$finalCombinedCssContent = self::appendToCombineCss($localAssetsExtra, $assetHref, $pathToAssetDir, $finalCombinedCssContent);
|
classes/OptimiseAssets/CombineJs.php
CHANGED
@@ -40,21 +40,24 @@ class CombineJs
|
|
40 |
|
41 |
$isDeferAppliedOnBodyCombineGroupNo = false;
|
42 |
|
43 |
-
// Speed up processing by getting the already existing final CSS file URI
|
44 |
-
// This will avoid parsing the HTML DOM and determine the combined URI paths for all the CSS files
|
45 |
-
$finalCacheList = OptimizeCommon::getAssetCachedData(self::$jsonStorageFile, OptimizeJs::getRelPathJsCacheDir(), 'js');
|
46 |
-
|
47 |
// $uriToFinalJsFile will always be relative ONLY within WP_CONTENT_DIR . self::getRelPathJsCacheDir()
|
48 |
// which is usually "wp-content/cache/asset-cleanup/js/"
|
49 |
|
50 |
// "true" would make it avoid checking the cache and always use the DOM Parser / RegExp
|
51 |
// for DEV purposes ONLY as it uses more resources
|
|
|
52 |
$skipCache = false;
|
53 |
|
54 |
if (isset($_GET['wpacu_no_cache']) || (defined('WPACU_NO_CACHE') && WPACU_NO_CACHE === true)) {
|
55 |
$skipCache = true;
|
56 |
}
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
if ( $skipCache || empty($finalCacheList) ) {
|
59 |
/*
|
60 |
* NO CACHING TRANSIENT; Parse the DOM
|
@@ -172,6 +175,13 @@ class CombineJs
|
|
172 |
$scriptNotCombinable = true;
|
173 |
}
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
if (isset($scriptAttributes['data-wpacu-to-be-preloaded-basic']) && $scriptAttributes['data-wpacu-to-be-preloaded-basic']) {
|
176 |
$scriptNotCombinable = true;
|
177 |
}
|
@@ -203,13 +213,20 @@ class CombineJs
|
|
203 |
if ( $localAssetPath = OptimizeCommon::getLocalAssetPath( $src, 'js' ) ) {
|
204 |
$scriptExtra = array();
|
205 |
|
206 |
-
if (
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
}
|
214 |
|
215 |
// Standard (could be multiple groups per $docLocationScript), Async & Defer, Async, Defer
|
@@ -470,8 +487,8 @@ HTML;
|
|
470 |
$htmlSourceAlt = preg_replace( '@<form action="#wpacu_wrap_assets" method="post">.*?</form>@si', '', $htmlSourceAlt );
|
471 |
}
|
472 |
|
473 |
-
//
|
474 |
-
if (strpos($
|
475 |
return $htmlSource;
|
476 |
}
|
477 |
|
@@ -505,8 +522,8 @@ HTML;
|
|
505 |
// Has "src" attribute and "defer" is not applied? Add it
|
506 |
if ($htmlAfterFirstCombinedDeferScriptMaybeChanged !== false) {
|
507 |
$htmlAfterFirstCombinedDeferScriptMaybeChanged = trim( preg_replace(
|
508 |
-
'
|
509 |
-
'src=\3\4\3 defer=\'defer\'',
|
510 |
$htmlAfterFirstCombinedDeferScriptMaybeChanged
|
511 |
) );
|
512 |
}
|
@@ -540,11 +557,11 @@ HTML;
|
|
540 |
if (strpos($loadedJsExceptionsPatterns, "\n")) {
|
541 |
// Multiple values (one per line)
|
542 |
foreach (explode("\n", $loadedJsExceptionsPatterns) as $loadedJsExceptionsPattern) {
|
543 |
-
$regExps[] = trim($loadedJsExceptionsPattern);
|
544 |
}
|
545 |
} else {
|
546 |
// Only one value?
|
547 |
-
$regExps[] = trim($loadedJsExceptionsPatterns);
|
548 |
}
|
549 |
}
|
550 |
|
@@ -554,7 +571,9 @@ HTML;
|
|
554 |
}
|
555 |
|
556 |
foreach ($regExps as $regExp) {
|
557 |
-
|
|
|
|
|
558 |
// Skip combination
|
559 |
return true;
|
560 |
}
|
@@ -592,8 +611,8 @@ HTML;
|
|
592 |
}
|
593 |
|
594 |
// Does it have a source map? Strip it
|
595 |
-
if (strpos($jsContent, 'sourceMappingURL') !== false) {
|
596 |
-
$jsContent = OptimizeCommon::stripSourceMap($jsContent);
|
597 |
}
|
598 |
|
599 |
$pathToAssetDir = OptimizeCommon::getPathToAssetDir($assetHref);
|
40 |
|
41 |
$isDeferAppliedOnBodyCombineGroupNo = false;
|
42 |
|
|
|
|
|
|
|
|
|
43 |
// $uriToFinalJsFile will always be relative ONLY within WP_CONTENT_DIR . self::getRelPathJsCacheDir()
|
44 |
// which is usually "wp-content/cache/asset-cleanup/js/"
|
45 |
|
46 |
// "true" would make it avoid checking the cache and always use the DOM Parser / RegExp
|
47 |
// for DEV purposes ONLY as it uses more resources
|
48 |
+
$finalCacheList = array();
|
49 |
$skipCache = false;
|
50 |
|
51 |
if (isset($_GET['wpacu_no_cache']) || (defined('WPACU_NO_CACHE') && WPACU_NO_CACHE === true)) {
|
52 |
$skipCache = true;
|
53 |
}
|
54 |
|
55 |
+
if (! $skipCache) {
|
56 |
+
// Speed up processing by getting the already existing final CSS file URI
|
57 |
+
// This will avoid parsing the HTML DOM and determine the combined URI paths for all the CSS files
|
58 |
+
$finalCacheList = OptimizeCommon::getAssetCachedData( self::$jsonStorageFile, OptimizeJs::getRelPathJsCacheDir(), 'js' );
|
59 |
+
}
|
60 |
+
|
61 |
if ( $skipCache || empty($finalCacheList) ) {
|
62 |
/*
|
63 |
* NO CACHING TRANSIENT; Parse the DOM
|
175 |
$scriptNotCombinable = true;
|
176 |
}
|
177 |
|
178 |
+
// Avoid any errors when code like the following one is used:
|
179 |
+
// wp.i18n.setLocaleData( localeData, domain );
|
180 |
+
// Because the inline JS is not appended to the combined JS, /wp-includes/js/dist/i18n.(min).js has to be called earlier (outside the combined JS file)
|
181 |
+
if ( ! OptimizeCommon::appendInlineCodeToCombineAssetType('js') && (strpos($src, '/wp-includes/js/dist/i18n.') !== false) ) {
|
182 |
+
$scriptNotCombinable = true;
|
183 |
+
}
|
184 |
+
|
185 |
if (isset($scriptAttributes['data-wpacu-to-be-preloaded-basic']) && $scriptAttributes['data-wpacu-to-be-preloaded-basic']) {
|
186 |
$scriptNotCombinable = true;
|
187 |
}
|
213 |
if ( $localAssetPath = OptimizeCommon::getLocalAssetPath( $src, 'js' ) ) {
|
214 |
$scriptExtra = array();
|
215 |
|
216 |
+
if ( OptimizeCommon::appendInlineCodeToCombineAssetType('js') ) {
|
217 |
+
if ( isset( $scriptAttributes['data-wpacu-script-handle'], $wpacuRegisteredScripts[ $scriptAttributes['data-wpacu-script-handle'] ]->extra ) ) {
|
218 |
+
$scriptExtra = $wpacuRegisteredScripts[ $scriptAttributes['data-wpacu-script-handle'] ]->extra;
|
219 |
+
}
|
220 |
+
|
221 |
+
$anyScriptTranslations = false;
|
222 |
+
|
223 |
+
if (method_exists('wp_scripts', 'print_translations')) {
|
224 |
+
$anyScriptTranslations = wp_scripts()->print_translations( $scriptAttributes['data-wpacu-script-handle'], false );
|
225 |
+
}
|
226 |
|
227 |
+
if ( $anyScriptTranslations ) {
|
228 |
+
$scriptExtra['translations'] = $anyScriptTranslations;
|
229 |
+
}
|
230 |
}
|
231 |
|
232 |
// Standard (could be multiple groups per $docLocationScript), Async & Defer, Async, Defer
|
487 |
$htmlSourceAlt = preg_replace( '@<form action="#wpacu_wrap_assets" method="post">.*?</form>@si', '', $htmlSourceAlt );
|
488 |
}
|
489 |
|
490 |
+
// No other SCRIPT left, stop here in this case
|
491 |
+
if (strpos($htmlSourceAlt, '<script') === false) {
|
492 |
return $htmlSource;
|
493 |
}
|
494 |
|
522 |
// Has "src" attribute and "defer" is not applied? Add it
|
523 |
if ($htmlAfterFirstCombinedDeferScriptMaybeChanged !== false) {
|
524 |
$htmlAfterFirstCombinedDeferScriptMaybeChanged = trim( preg_replace(
|
525 |
+
'#\ssrc(\s+|)=(\s+|)(|"|\'|\s+)(' . preg_quote( $scriptAttributes['src'], '/' ) . ')(\3)#si',
|
526 |
+
' src=\3\4\3 defer=\'defer\'',
|
527 |
$htmlAfterFirstCombinedDeferScriptMaybeChanged
|
528 |
) );
|
529 |
}
|
557 |
if (strpos($loadedJsExceptionsPatterns, "\n")) {
|
558 |
// Multiple values (one per line)
|
559 |
foreach (explode("\n", $loadedJsExceptionsPatterns) as $loadedJsExceptionsPattern) {
|
560 |
+
$regExps[] = '#'.trim($loadedJsExceptionsPattern).'#';
|
561 |
}
|
562 |
} else {
|
563 |
// Only one value?
|
564 |
+
$regExps[] = '#'.trim($loadedJsExceptionsPatterns).'#';
|
565 |
}
|
566 |
}
|
567 |
|
571 |
}
|
572 |
|
573 |
foreach ($regExps as $regExp) {
|
574 |
+
$regExp = Misc::purifyRegexValue($regExp);
|
575 |
+
|
576 |
+
if ( @preg_match( $regExp, $src ) || ( strpos($src, $regExp) !== false ) ) {
|
577 |
// Skip combination
|
578 |
return true;
|
579 |
}
|
611 |
}
|
612 |
|
613 |
// Does it have a source map? Strip it
|
614 |
+
if (strpos($jsContent, '//# sourceMappingURL=') !== false) {
|
615 |
+
$jsContent = OptimizeCommon::stripSourceMap($jsContent, 'js');
|
616 |
}
|
617 |
|
618 |
$pathToAssetDir = OptimizeCommon::getPathToAssetDir($assetHref);
|
classes/OptimiseAssets/MinifyCss.php
CHANGED
@@ -31,6 +31,21 @@ class MinifyCss
|
|
31 |
return $cssContent;
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
$minifier = new \MatthiasMullie\Minify\CSS( $cssContent );
|
35 |
|
36 |
if ( $forInlineStyle ) {
|
@@ -41,6 +56,16 @@ class MinifyCss
|
|
41 |
|
42 |
$minifiedContent = trim( $minifier->minify() );
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
if ($checkForAlreadyMinifiedShaOne && $minifiedContent === $cssContent) {
|
45 |
// If the resulting content is the same, mark it as minified to avoid the minify process next time
|
46 |
OptimizeCommon::originalContentMarkAsAlreadyMinified( $sha1OriginalContent, 'styles' );
|
31 |
return $cssContent;
|
32 |
}
|
33 |
|
34 |
+
// [CUSTOM BUG FIX]
|
35 |
+
// Encode the special matched content to avoid any wrong minification from the minifier
|
36 |
+
$hasVarWithZeroUnit = false;
|
37 |
+
|
38 |
+
preg_match_all('#--([a-zA-Z0-9_-]+):(\s+)0(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)#', $cssContent, $cssVariablesMatches);
|
39 |
+
|
40 |
+
if (isset($cssVariablesMatches[0]) && ! empty($cssVariablesMatches[0])) {
|
41 |
+
$hasVarWithZeroUnit = true;
|
42 |
+
|
43 |
+
foreach ($cssVariablesMatches[0] as $zeroUnitMatch) {
|
44 |
+
$cssContent = str_replace( $zeroUnitMatch, '[wpacu]' . base64_encode( $zeroUnitMatch ) . '[/wpacu]', $cssContent );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
// [/CUSTOM BUG FIX]
|
48 |
+
|
49 |
$minifier = new \MatthiasMullie\Minify\CSS( $cssContent );
|
50 |
|
51 |
if ( $forInlineStyle ) {
|
56 |
|
57 |
$minifiedContent = trim( $minifier->minify() );
|
58 |
|
59 |
+
// [CUSTOM BUG FIX]
|
60 |
+
// Restore the original content
|
61 |
+
if ($hasVarWithZeroUnit) {
|
62 |
+
foreach ( $cssVariablesMatches[0] as $zeroUnitMatch ) {
|
63 |
+
$zeroUnitMatchAlt = str_replace(': 0', ':0', $zeroUnitMatch); // remove the space
|
64 |
+
$minifiedContent = str_replace( '[wpacu]' . base64_encode( $zeroUnitMatch ) . '[/wpacu]', $zeroUnitMatchAlt, $minifiedContent );
|
65 |
+
}
|
66 |
+
}
|
67 |
+
// [/CUSTOM BUG FIX]
|
68 |
+
|
69 |
if ($checkForAlreadyMinifiedShaOne && $minifiedContent === $cssContent) {
|
70 |
// If the resulting content is the same, mark it as minified to avoid the minify process next time
|
71 |
OptimizeCommon::originalContentMarkAsAlreadyMinified( $sha1OriginalContent, 'styles' );
|
classes/OptimiseAssets/OptimizeCommon.php
CHANGED
@@ -1400,12 +1400,32 @@ SQL;
|
|
1400 |
|
1401 |
/**
|
1402 |
* @param $assetContent
|
|
|
1403 |
*
|
1404 |
-
* @return
|
1405 |
*/
|
1406 |
-
public static function stripSourceMap($assetContent)
|
1407 |
{
|
1408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1409 |
}
|
1410 |
|
1411 |
/**
|
1400 |
|
1401 |
/**
|
1402 |
* @param $assetContent
|
1403 |
+
* @param $forAssetType
|
1404 |
*
|
1405 |
+
* @return string|string[]
|
1406 |
*/
|
1407 |
+
public static function stripSourceMap($assetContent, $forAssetType)
|
1408 |
{
|
1409 |
+
if ($forAssetType === 'css') {
|
1410 |
+
$sourceMappingURLStr = '/*# sourceMappingURL=';
|
1411 |
+
$sourceMappingURLStrReplaceStart = '/*';
|
1412 |
+
} else {
|
1413 |
+
$sourceMappingURLStr = '//# sourceMappingURL=';
|
1414 |
+
$sourceMappingURLStrReplaceStart = '//';
|
1415 |
+
}
|
1416 |
+
|
1417 |
+
$assetContent = trim($assetContent);
|
1418 |
+
|
1419 |
+
if (strpos($assetContent, "\n") !== false) {
|
1420 |
+
$allContentLines = explode("\n", $assetContent);
|
1421 |
+
$lastContentLine = end($allContentLines);
|
1422 |
+
|
1423 |
+
if (strpos($lastContentLine, $sourceMappingURLStr) !== false) {
|
1424 |
+
return str_replace( $sourceMappingURLStr, $sourceMappingURLStrReplaceStart.'# Current File Updated by '.WPACU_PLUGIN_TITLE.' - Original Source Map: ', $assetContent );
|
1425 |
+
}
|
1426 |
+
}
|
1427 |
+
|
1428 |
+
return $assetContent;
|
1429 |
}
|
1430 |
|
1431 |
/**
|
classes/OptimiseAssets/OptimizeCss.php
CHANGED
@@ -367,9 +367,10 @@ class OptimizeCss
|
|
367 |
return false;
|
368 |
}
|
369 |
|
|
|
370 |
// Does it have a source map? Strip it
|
371 |
-
if (strpos($cssContent, 'sourceMappingURL') !== false) {
|
372 |
-
$cssContent = OptimizeCommon::stripSourceMap($cssContent);
|
373 |
}
|
374 |
|
375 |
$cssContent = self::maybeFixCssContent( $cssContent, $pathToAssetDir . '/' ); // Path
|
@@ -793,15 +794,30 @@ class OptimizeCss
|
|
793 |
$newLinkSourceTag = str_ireplace('<link ', '<link data-wpacu-link-rel-href-before="'.$sourceUrlRel.'" ', $newLinkSourceTag);
|
794 |
}
|
795 |
|
796 |
-
|
797 |
-
$newLinkSourceTag = str_replace('.css&ver', '.css?ver', $newLinkSourceTag);
|
798 |
-
$toStrip = Misc::extractBetween($newLinkSourceTag, '?ver', ' ');
|
799 |
|
800 |
-
|
801 |
-
|
802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
803 |
}
|
804 |
|
|
|
|
|
|
|
|
|
|
|
|
|
805 |
return $newLinkSourceTag;
|
806 |
}
|
807 |
|
@@ -973,8 +989,8 @@ class OptimizeCss
|
|
973 |
}
|
974 |
|
975 |
// Does it have a source map? Strip it
|
976 |
-
if (strpos($cssContent, 'sourceMappingURL') !== false) {
|
977 |
-
$cssContent = OptimizeCommon::stripSourceMap($cssContent);
|
978 |
}
|
979 |
/* [END] Change CSS Content */
|
980 |
|
367 |
return false;
|
368 |
}
|
369 |
|
370 |
+
// Continue, as changes are to be made
|
371 |
// Does it have a source map? Strip it
|
372 |
+
if (strpos($cssContent, '/*# sourceMappingURL=') !== false) {
|
373 |
+
$cssContent = OptimizeCommon::stripSourceMap($cssContent, 'css');
|
374 |
}
|
375 |
|
376 |
$cssContent = self::maybeFixCssContent( $cssContent, $pathToAssetDir . '/' ); // Path
|
794 |
$newLinkSourceTag = str_ireplace('<link ', '<link data-wpacu-link-rel-href-before="'.$sourceUrlRel.'" ', $newLinkSourceTag);
|
795 |
}
|
796 |
|
797 |
+
preg_match_all( '#\shref=(["\'])(.*?)(["\'])#', $newLinkSourceTag, $outputMatchesSrc );
|
|
|
|
|
798 |
|
799 |
+
// No space from the matching and ? should be there
|
800 |
+
if (isset( $outputMatchesSrc[2][0] ) && ( strpos( $outputMatchesSrc[2][0], ' ' ) === false )) {
|
801 |
+
if ( strpos( $outputMatchesSrc[2][0], '?' ) !== false ) {
|
802 |
+
// Strip things like ?ver=
|
803 |
+
list( , $toStrip ) = explode( '?', $outputMatchesSrc[2][0] );
|
804 |
+
$toStrip = '?' . trim( $toStrip );
|
805 |
+
$newLinkSourceTag = str_replace( $toStrip, '', $newLinkSourceTag );
|
806 |
+
}
|
807 |
+
|
808 |
+
if ( strpos( $outputMatchesSrc[2][0], '&ver' ) !== false ) {
|
809 |
+
// Replace any .js&ver with .js
|
810 |
+
$toStrip = strrchr($outputMatchesSrc[2][0], '&ver');
|
811 |
+
$newLinkSourceTag = str_replace( $toStrip, '', $newLinkSourceTag );
|
812 |
+
}
|
813 |
}
|
814 |
|
815 |
+
global $wp_version;
|
816 |
+
$newLinkSourceTag = str_replace('.css&ver='.$wp_version, '.css', $newLinkSourceTag);
|
817 |
+
$newLinkSourceTag = str_replace('.css&ver=', '.css', $newLinkSourceTag);
|
818 |
+
|
819 |
+
$newLinkSourceTag = preg_replace('!\s+!', ' ', $newLinkSourceTag); // replace multiple spaces with only one space
|
820 |
+
|
821 |
return $newLinkSourceTag;
|
822 |
}
|
823 |
|
989 |
}
|
990 |
|
991 |
// Does it have a source map? Strip it
|
992 |
+
if (strpos($cssContent, '/*# sourceMappingURL=') !== false) {
|
993 |
+
$cssContent = OptimizeCommon::stripSourceMap($cssContent, 'css');
|
994 |
}
|
995 |
/* [END] Change CSS Content */
|
996 |
|
classes/OptimiseAssets/OptimizeJs.php
CHANGED
@@ -350,6 +350,8 @@ class OptimizeJs
|
|
350 |
return array('content' => $jsContent);
|
351 |
}
|
352 |
|
|
|
|
|
353 |
/* [START] Change JS Content */
|
354 |
if ($doJsMinify) {
|
355 |
$jsContent = MinifyJs::applyMinification($jsContent);
|
@@ -363,13 +365,13 @@ class OptimizeJs
|
|
363 |
}
|
364 |
/* [END] Change JS Content */
|
365 |
|
366 |
-
|
367 |
-
|
368 |
-
//
|
369 |
-
|
370 |
-
$jsContent = OptimizeCommon::stripSourceMap($jsContent);
|
371 |
}
|
372 |
|
|
|
373 |
return array('content' => $jsContent , 'content_after_alter_to_compare' => $jsContentAfterAlterToCompare);
|
374 |
}
|
375 |
|
@@ -396,7 +398,7 @@ class OptimizeJs
|
|
396 |
}
|
397 |
|
398 |
// For debugging purposes
|
399 |
-
if (isset($_GET['wpacu_no_cache'])) { $useCacheForInlineScript = false; }
|
400 |
|
401 |
if ($useCacheForInlineScript) {
|
402 |
// Anything in the cache? Take it from there and don't spend resources with the minification
|
@@ -595,12 +597,22 @@ class OptimizeJs
|
|
595 |
$sourceUrlRel = is_array($sourceUrl) ? OptimizeCommon::getSourceRelPath($sourceUrl[0]) : OptimizeCommon::getSourceRelPath($sourceUrl);
|
596 |
$newScriptSourceTag = str_ireplace('<script ', '<script data-wpacu-script-rel-src-before="'.$sourceUrlRel.'" ', $newScriptSourceTag);
|
597 |
|
598 |
-
|
599 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
600 |
|
601 |
-
|
602 |
-
|
603 |
-
|
|
|
|
|
604 |
}
|
605 |
|
606 |
global $wp_version;
|
@@ -1109,7 +1121,11 @@ class OptimizeJs
|
|
1109 |
}
|
1110 |
}
|
1111 |
|
1112 |
-
$scriptTranslations =
|
|
|
|
|
|
|
|
|
1113 |
|
1114 |
return array(
|
1115 |
'translations' => trim($scriptTranslations),
|
@@ -1128,7 +1144,7 @@ class OptimizeJs
|
|
1128 |
);
|
1129 |
}
|
1130 |
|
1131 |
-
return array('data' => '', 'before' => '', 'after' => '');
|
1132 |
}
|
1133 |
|
1134 |
/**
|
@@ -1153,7 +1169,12 @@ class OptimizeJs
|
|
1153 |
$output = '';
|
1154 |
|
1155 |
if ($position === 'translations') {
|
1156 |
-
$translations =
|
|
|
|
|
|
|
|
|
|
|
1157 |
if ( $translations ) {
|
1158 |
$output = sprintf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $typeAttr, esc_attr( $handle ), $translations );
|
1159 |
}
|
350 |
return array('content' => $jsContent);
|
351 |
}
|
352 |
|
353 |
+
$jsContentBefore = $jsContent;
|
354 |
+
|
355 |
/* [START] Change JS Content */
|
356 |
if ($doJsMinify) {
|
357 |
$jsContent = MinifyJs::applyMinification($jsContent);
|
365 |
}
|
366 |
/* [END] Change JS Content */
|
367 |
|
368 |
+
// Does it have a source map? Strip it only if any optimization was already applied
|
369 |
+
// As, otherwise, there's no point in creating a caching file, since there are no changes worth made to the file
|
370 |
+
if (($jsContentBefore !== $jsContent) && (strpos($jsContent, '// #sourceMappingURL') !== false) && Misc::endsWith(trim($jsContent), '.map')) {
|
371 |
+
$jsContent = OptimizeCommon::stripSourceMap($jsContent, 'js');
|
|
|
372 |
}
|
373 |
|
374 |
+
$jsContentAfterAlterToCompare = $jsContent; // new possible values
|
375 |
return array('content' => $jsContent , 'content_after_alter_to_compare' => $jsContentAfterAlterToCompare);
|
376 |
}
|
377 |
|
398 |
}
|
399 |
|
400 |
// For debugging purposes
|
401 |
+
if (isset($_GET['wpacu_no_cache']) || (defined('WPACU_NO_CACHE') && WPACU_NO_CACHE === true)) { $useCacheForInlineScript = false; }
|
402 |
|
403 |
if ($useCacheForInlineScript) {
|
404 |
// Anything in the cache? Take it from there and don't spend resources with the minification
|
597 |
$sourceUrlRel = is_array($sourceUrl) ? OptimizeCommon::getSourceRelPath($sourceUrl[0]) : OptimizeCommon::getSourceRelPath($sourceUrl);
|
598 |
$newScriptSourceTag = str_ireplace('<script ', '<script data-wpacu-script-rel-src-before="'.$sourceUrlRel.'" ', $newScriptSourceTag);
|
599 |
|
600 |
+
preg_match_all( '#\ssrc=(["\'])(.*?)(["\'])#', $scriptSourceTag, $outputMatchesSrc );
|
601 |
+
|
602 |
+
// No space from the matching and ? should be there
|
603 |
+
if (isset( $outputMatchesSrc[2][0] ) && ( strpos( $outputMatchesSrc[2][0], ' ' ) === false )) {
|
604 |
+
if ( strpos( $outputMatchesSrc[2][0], '?' ) !== false ) {
|
605 |
+
// Strip things like ?ver=
|
606 |
+
list( , $toStrip ) = explode( '?', $outputMatchesSrc[2][0] );
|
607 |
+
$toStrip = '?' . trim( $toStrip );
|
608 |
+
$newScriptSourceTag = str_replace( $toStrip, '', $newScriptSourceTag );
|
609 |
+
}
|
610 |
|
611 |
+
if ( strpos( $outputMatchesSrc[2][0], '&ver' ) !== false ) {
|
612 |
+
// Replace any .js&ver with .js
|
613 |
+
$toStrip = strrchr($outputMatchesSrc[2][0], '&ver');
|
614 |
+
$newScriptSourceTag = str_replace( $toStrip, '', $newScriptSourceTag );
|
615 |
+
}
|
616 |
}
|
617 |
|
618 |
global $wp_version;
|
1121 |
}
|
1122 |
}
|
1123 |
|
1124 |
+
$scriptTranslations = '';
|
1125 |
+
|
1126 |
+
if (method_exists('wp_scripts', 'print_translations')) {
|
1127 |
+
$scriptTranslations = wp_scripts()->print_translations( $scriptHandle, false );
|
1128 |
+
}
|
1129 |
|
1130 |
return array(
|
1131 |
'translations' => trim($scriptTranslations),
|
1144 |
);
|
1145 |
}
|
1146 |
|
1147 |
+
return array('translations' => '', 'data' => '', 'before' => '', 'after' => '');
|
1148 |
}
|
1149 |
|
1150 |
/**
|
1169 |
$output = '';
|
1170 |
|
1171 |
if ($position === 'translations') {
|
1172 |
+
$translations = false;
|
1173 |
+
|
1174 |
+
if (method_exists('wp_scripts', 'print_translations')) {
|
1175 |
+
$translations = $wp_scripts->print_translations( $handle, false );
|
1176 |
+
}
|
1177 |
+
|
1178 |
if ( $translations ) {
|
1179 |
$output = sprintf( "<script%s id='%s-js-translations'>\n%s\n</script>\n", $typeAttr, esc_attr( $handle ), $translations );
|
1180 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: minify css, minify javascript, defer css javascript, page speed, dequeue,
|
|
4 |
Donate link: https://www.gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 5.6.1
|
7 |
-
Stable tag: 1.3.7.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
@@ -190,6 +190,16 @@ With the recently released "Test Mode" feature, you can safely unload assets on
|
|
190 |
4. Homepage CSS & JS Management (List sorted by location)
|
191 |
|
192 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
= 1.3.7.4 =
|
194 |
* Improved the caching mechanism: The most recently created files are never deleted in case HTML pages that weren't cleared for weeks or more would still load them successfully; Once "ver" is updated, then the now old file will be cleared in a couple of days (e.g. at least one day + the number of days set in "Settings" -> "Plugin Usage Preferences" -> "Clear previously cached CSS/JS files older than (x) days")
|
195 |
* Combine JS Update: Make sure the inline "translations" associated with a JS file is appended to the combined JS files, as this would also avoid possible errors such as "Uncaught ReferenceError: wp is not defined"
|
4 |
Donate link: https://www.gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
|
5 |
Requires at least: 4.5
|
6 |
Tested up to: 5.6.1
|
7 |
+
Stable tag: 1.3.7.5
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl.html
|
10 |
|
190 |
4. Homepage CSS & JS Management (List sorted by location)
|
191 |
|
192 |
== Changelog ==
|
193 |
+
= 1.3.7.5 =
|
194 |
+
* Higher accuracy in detecting the source map for CSS & JS files in order to update it if the caching file is created; Make sure no caching file is created if there's no change already made to the JS content (e.g. minify), otherwise, it doesn't make sense to only change the source map
|
195 |
+
* Delete an option related to the plugin (from {wp_}options) instead of updating it with an empty value
|
196 |
+
* Do not trigger the plugin when Zion Page Builder from Kallyas theme is used to avoid using extra resources or print any assets below the page when "Manage in the front-end" is enabled, thus, cluttering the page
|
197 |
+
* Fix: Sometimes, due to multiple query strings the optimized asset URLs weren't replacing the original asset URLs correctly (e.g. /?version=value&ver=1.2)
|
198 |
+
* Fix (CSS Minify): Do not update "0px" to "0" from a global declared variable (e.g. ":root { --some-var: 0px; }" should not have "px" removed)
|
199 |
+
* Fix: Avoid preg_match() errors coming from any RegEx from the following option: "Do not combine the (CSS|JavaScript) files matching the patterns below (one per line)"
|
200 |
+
* Fix: If WordPress version is below 5, an error is generated when print_translations() is triggered because the method does not exists within wp_scripts()
|
201 |
+
* Fix: Prevent combined CSS files from generating from just one file (useless) when the array is filled twice by mistake with the same file path
|
202 |
+
|
203 |
= 1.3.7.4 =
|
204 |
* Improved the caching mechanism: The most recently created files are never deleted in case HTML pages that weren't cleared for weeks or more would still load them successfully; Once "ver" is updated, then the now old file will be cleared in a couple of days (e.g. at least one day + the number of days set in "Settings" -> "Plugin Usage Preferences" -> "Clear previously cached CSS/JS files older than (x) days")
|
205 |
* Combine JS Update: Make sure the inline "translations" associated with a JS file is appended to the combined JS files, as this would also avoid possible errors such as "Uncaught ReferenceError: wp is not defined"
|
wpacu.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
* Plugin Name: Asset CleanUp: Page Speed Booster
|
4 |
* Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
|
5 |
-
* Version: 1.3.7.
|
6 |
* Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
|
7 |
* Author: Gabe Livan
|
8 |
* Author URI: http://gabelivan.com/
|
@@ -27,7 +27,7 @@ if ( (defined('WPACU_PRO_NO_LITE_NEEDED') && WPACU_PRO_NO_LITE_NEEDED !== false
|
|
27 |
|
28 |
// Is the Pro version triggered before the Lite one and are both plugins active?
|
29 |
if (! defined('WPACU_PLUGIN_VERSION')) {
|
30 |
-
define('WPACU_PLUGIN_VERSION', '1.3.7.
|
31 |
}
|
32 |
|
33 |
// Exit if accessed directly
|
2 |
/*
|
3 |
* Plugin Name: Asset CleanUp: Page Speed Booster
|
4 |
* Plugin URI: https://wordpress.org/plugins/wp-asset-clean-up/
|
5 |
+
* Version: 1.3.7.5
|
6 |
* Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
|
7 |
* Author: Gabe Livan
|
8 |
* Author URI: http://gabelivan.com/
|
27 |
|
28 |
// Is the Pro version triggered before the Lite one and are both plugins active?
|
29 |
if (! defined('WPACU_PLUGIN_VERSION')) {
|
30 |
+
define('WPACU_PLUGIN_VERSION', '1.3.7.5');
|
31 |
}
|
32 |
|
33 |
// Exit if accessed directly
|