Asset CleanUp: Page Speed Booster - Version 1.3.3.6

Version Description

  • New Feature: Google Fonts Optimization: Combine multiple font requests into fewer requests; Option to add "font-display" CSS property (PageSpeed Insights Reference: "Ensure text remains visible during webfont load")
Download this release

Release Info

Developer gabelivan
Plugin Icon 128x128 Asset CleanUp: Page Speed Booster
Version 1.3.3.6
Comparing to
See all releases

Code changes from version 1.3.3.5 to 1.3.3.6

classes/OptimiseAssets/GoogleFonts.php ADDED
@@ -0,0 +1,359 @@
1
+ <?php
2
+ namespace WpAssetCleanUp\OptimiseAssets;
3
+
4
+ use WpAssetCleanUp\Main;
5
+
6
+ /**
7
+ * Class GoogleFonts
8
+ * @package WpAssetCleanUp\OptimiseAssets
9
+ */
10
+ class GoogleFonts
11
+ {
12
+ /**
13
+ * @var string
14
+ */
15
+ public static $containsStr = 'fonts.googleapis.com/css?';
16
+
17
+ /**
18
+ *
19
+ */
20
+ const COMBINED_LINK_DEL = '<meta name="wpacu-generator" content="ASSET CLEANUP COMBINED LINK LOCATION">';
21
+
22
+ /**
23
+ *
24
+ */
25
+ public function init()
26
+ {
27
+ add_action('init', function() {
28
+ // don't apply any changes if not in the front-end view (e.g. Dashboard view)
29
+ // or test mode is enabled and a guest user is accessing the page
30
+ if (is_admin() || Main::instance()->preventAssetsSettings()) {
31
+ return;
32
+ }
33
+
34
+ add_filter('style_loader_src', array($this, 'alterGoogleFontLink'));
35
+ }, 20);
36
+
37
+ add_action('wp_loaded', function() {
38
+ // don't apply any changes if not in the front-end view (e.g. Dashboard view)
39
+ // or test mode is enabled and a guest user is accessing the page
40
+ if (is_admin() || Main::instance()->preventAssetsSettings()) {
41
+ return;
42
+ }
43
+
44
+ ob_start(function($htmlSource) {
45
+ // Cleaner HTML Source
46
+ $altHtmlSource = preg_replace('#<noscript>(.*?)</noscript>#si', '', $htmlSource);
47
+
48
+ // Do not continue if there is no single reference to the string we look for in the clean HTML source
49
+ if (stripos($altHtmlSource, self::$containsStr) === false) {
50
+ return $htmlSource;
51
+ }
52
+
53
+ // Get all valid LINKs that have the $string within them
54
+ $strContainsFormat = preg_quote(self::$containsStr, '/');
55
+ $regExpPattern = '#<link[^>]*' . $strContainsFormat . '.*(>)#Usmi';
56
+
57
+ preg_match_all($regExpPattern, $altHtmlSource, $matchesFromLinkTags, PREG_SET_ORDER);
58
+
59
+ // Needs to match at least one to carry on with the replacements
60
+ if (isset($matchesFromLinkTags[0]) && ! empty($matchesFromLinkTags[0])) {
61
+ $finalCombinableLinks = $preloadedLinks = array();
62
+
63
+ foreach ($matchesFromLinkTags as $linkIndex => $linkTagArray) {
64
+ $linkTag = $finalLinkTag = trim(trim($linkTagArray[0], '"\''));
65
+ preg_match_all('#href=("|\')' . '(.*)' . '("|\')#Usmi', $linkTag, $outputMatches);
66
+ $linkHrefOriginal = $finalLinkHref = trim($outputMatches[2][0], '"\'');
67
+
68
+ // If anything is set apart from '[none set]', proceed
69
+ if (Main::instance()->settings['google_fonts_display']) {
70
+ $newLinkHref = $finalLinkHref = self::alterGoogleFontLink($linkHrefOriginal);
71
+
72
+ if ($newLinkHref !== $linkHrefOriginal) {
73
+ $finalLinkTag = str_replace($linkHrefOriginal, $newLinkHref, $linkTag);
74
+
75
+ // Finally, alter the HTML source
76
+ $htmlSource = str_replace($linkTag, $finalLinkTag, $htmlSource);
77
+ }
78
+ }
79
+
80
+ if (preg_match('/rel=("\')preload("\')/i', $finalLinkTag)
81
+ || strpos($finalLinkTag, 'data-wpacu-to-be-preloaded-basic')) {
82
+ $preloadedLinks[] = $finalLinkHref;
83
+ }
84
+
85
+ $finalCombinableLinks[] = array('href' => $finalLinkHref, 'tag' => $finalLinkTag);
86
+ }
87
+
88
+ $preloadedLinks = array_unique($preloadedLinks);
89
+
90
+ // Remove data for preloaded LINKs
91
+ if (! empty($preloadedLinks)) {
92
+ foreach ($finalCombinableLinks as $fclIndex => $combinableLinkData) {
93
+ if (in_array($combinableLinkData['href'], $preloadedLinks)) {
94
+ unset($finalCombinableLinks[$fclIndex]);
95
+ }
96
+ }
97
+ }
98
+
99
+ // Only proceed with the combine if there's obviously at least 2 combinable URL requests to Google Fonts
100
+ if (count($finalCombinableLinks) > 1 && Main::instance()->settings['google_fonts_combine']) {
101
+ $htmlSource = self::combineGoogleFontLinks($finalCombinableLinks, $htmlSource);
102
+ }
103
+ }
104
+
105
+ $htmlSource = self::alterGoogleFontUrlFromInlineStyleTags($htmlSource);
106
+
107
+ return $htmlSource;
108
+ });
109
+ }, PHP_INT_MAX);
110
+ }
111
+
112
+ /**
113
+ * @param $linkHrefOriginal
114
+ * @param bool $escHtml
115
+ *
116
+ * @return string
117
+ */
118
+ public static function alterGoogleFontLink($linkHrefOriginal, $escHtml = true)
119
+ {
120
+ // Do not continue if it doesn't contain the right string or it contains 'display=' or there is no value set for "font-display"
121
+ if (stripos($linkHrefOriginal, self::$containsStr) === false || strpos($linkHrefOriginal, 'display=') !== false || ! Main::instance()->settings['google_fonts_display']) {
122
+ // Return original source
123
+ return $linkHrefOriginal;
124
+ }
125
+
126
+ $altLinkHref = str_replace('&#038;', '&', $linkHrefOriginal);
127
+
128
+ $urlQuery = parse_url($altLinkHref, PHP_URL_QUERY);
129
+ parse_str($urlQuery, $outputStr);
130
+
131
+ // Is there no "display" or there is but it has an empty value? Append the one we have in the "Settings" - "Google Fonts"
132
+ if ( ! isset($outputStr['display']) || (isset($outputStr['display']) && $outputStr['display'] === '') ) {
133
+ $outputStr['display'] = Main::instance()->settings['google_fonts_display'];
134
+
135
+ list($linkHrefFirstPart) = explode('?', $linkHrefOriginal);
136
+
137
+ // Returned the updated source with the 'display' parameter appended to it
138
+ $afterQuestionMark = http_build_query($outputStr);
139
+
140
+ if ($escHtml) {
141
+ $afterQuestionMark = esc_attr($afterQuestionMark);
142
+ }
143
+
144
+ return $linkHrefFirstPart . '?' . $afterQuestionMark;
145
+ }
146
+
147
+ // Return original source
148
+ return $linkHrefOriginal;
149
+ }
150
+
151
+ /**
152
+ * @param $htmlSource
153
+ *
154
+ * @return mixed
155
+ */
156
+ public static function alterGoogleFontUrlFromInlineStyleTags($htmlSource)
157
+ {
158
+ if (! preg_match('/@import(\s+)url\(/i', $htmlSource)) {
159
+ return $htmlSource;
160
+ }
161
+
162
+ $regExpPattern = '#<\s*?style\b[^>]*>(.*?)</style\b[^>]*>#s';
163
+ preg_match_all($regExpPattern, $htmlSource, $styleMatches, PREG_SET_ORDER);
164
+
165
+ if (empty($styleMatches)) {
166
+ return $htmlSource;
167
+ }
168
+
169
+ // Go through each STYLE tag
170
+ foreach ($styleMatches as $styleInlineArray) {
171
+ list($styleInlineTag, $styleInlineContent) = $styleInlineArray;
172
+
173
+ // Is the content relevant?
174
+ if (! preg_match('/@import(\s+|)(url|\(|\'|")/i', $styleInlineContent)
175
+ || stripos($styleInlineContent, 'fonts.googleapis.com') === false) {
176
+ continue;
177
+ }
178
+
179
+ // Do any alteration to the URL of the Google Font
180
+ $newCssOutput = self::alterGoogleFontUrlFromCssContent($styleInlineTag);
181
+
182
+ $htmlSource = str_replace($styleInlineTag, $newCssOutput, $htmlSource);
183
+ }
184
+
185
+ return $htmlSource;
186
+ }
187
+
188
+ /**
189
+ * @param $cssContent
190
+ *
191
+ * @return mixed
192
+ */
193
+ public static function alterGoogleFontUrlFromCssContent($cssContent)
194
+ {
195
+ if (stripos($cssContent, 'fonts.googleapis.com') === false) {
196
+ return $cssContent;
197
+ }
198
+
199
+ $regExps = array('/@import(\s+)url\((.*?)\)(|\s+)\;/i', '/@import(\s+|)(\(|\'|")(.*?)(\'|"|\))\;/i');
200
+
201
+ $newCssOutput = $cssContent;
202
+
203
+ foreach ($regExps as $regExpIndex => $regExpPattern) {
204
+ preg_match_all($regExpPattern, $cssContent, $matchesFromInlineCode, PREG_SET_ORDER);
205
+
206
+ if (! empty($matchesFromInlineCode)) {
207
+ foreach ($matchesFromInlineCode as $matchIndex => $matchesFromInlineCodeArray) {
208
+ if ($regExpIndex === 0) {
209
+ $googleApisUrl = trim($matchesFromInlineCodeArray[2], '"\' ');
210
+ } else {
211
+ $googleApisUrl = trim($matchesFromInlineCodeArray[3], '"\' ');
212
+ }
213
+
214
+ // It has to be a Google Fonts API link
215
+ if (stripos($googleApisUrl, 'fonts.googleapis.com') === false) {
216
+ continue;
217
+ }
218
+
219
+ $newGoogleApisUrl = self::alterGoogleFontLink($googleApisUrl, false);
220
+
221
+ $newCssOutput = str_replace($googleApisUrl, $newGoogleApisUrl, $newCssOutput);
222
+ }
223
+ }
224
+ }
225
+
226
+ return $newCssOutput;
227
+ }
228
+
229
+ /**
230
+ * @param $finalLinks
231
+ * @param $htmlSource
232
+ *
233
+ * @return false|mixed|string|void
234
+ */
235
+ public static function combineGoogleFontLinks($finalLinks, $htmlSource)
236
+ {
237
+ $fontsArray = array();
238
+
239
+ foreach ($finalLinks as $finalLinkIndex => $finalLinkData) {
240
+ $finalLinkHref = $finalLinkData['href'];
241
+ $finalLinkHref = str_replace('&#038;', '&', $finalLinkHref);
242
+
243
+ $queries = parse_url($finalLinkHref, PHP_URL_QUERY);
244
+ parse_str($queries, $fontQueries);
245
+
246
+ if (! array_key_exists('family', $fontQueries) || array_key_exists('text', $fontQueries)) {
247
+ continue;
248
+ }
249
+
250
+ // Strip the existing tag, leave a mark where the final combined LINK will be placed
251
+ $stripTagWith = ($finalLinkIndex === 0) ? self::COMBINED_LINK_DEL : '';
252
+ $finalLinkTag = $finalLinkData['tag'];
253
+
254
+ $htmlSource = str_ireplace(array($finalLinkTag."\n", $finalLinkTag), $stripTagWith, $htmlSource);
255
+
256
+ $family = trim($fontQueries['family']);
257
+ $family = trim($family, '|');
258
+
259
+ if (! $family) {
260
+ continue;
261
+ }
262
+
263
+ if (strpos($family, '|') !== false) {
264
+ // More than one family per request?
265
+ foreach (explode('|', $family) as $familyOne) {
266
+ if (strpos($familyOne, ':') !== false) {
267
+ // They have types
268
+ list ($familyRaw, $familyTypes) = explode(':', $familyOne);
269
+ $fontsArray['families'][$familyRaw]['types'][] = $familyTypes;
270
+ } else {
271
+ // They do not have types
272
+ $familyRaw = $familyOne;
273
+ $fontsArray['families'][$familyRaw]['types'][] = array();
274
+ }
275
+ }
276
+ } elseif (strpos($family, ':') !== false) {
277
+ list ($familyRaw, $familyTypes) = explode(':', $family);
278
+ $fontsArray['families'][$familyRaw]['types'][] = $familyTypes;
279
+ } else {
280
+ $familyRaw = $family;
281
+ $fontsArray['families'][$familyRaw]['types'] = false;
282
+ }
283
+
284
+ if (array_key_exists('subset', $fontQueries)) {
285
+ // More than one subset per request?
286
+ if (strpos($fontQueries['subset'], ',') !== false) {
287
+ $multipleSubsets = explode(',', trim($fontQueries['subset'], ','));
288
+
289
+ foreach ($multipleSubsets as $subset) {
290
+ $fontsArray['subsets'][] = trim($subset);
291
+ }
292
+ } else {
293
+ // Only one subset
294
+ $fontsArray['subsets'][] = $fontQueries['subset'];
295
+ }
296
+ }
297
+
298
+ if (array_key_exists('effect', $fontQueries)) {
299
+ // More than one subset per request?
300
+ if (strpos($fontQueries['effect'], '|') !== false) {
301
+ $multipleSubsets = explode('|', trim($fontQueries['effect'], '|'));
302
+
303
+ foreach ($multipleSubsets as $subset) {
304
+ $fontsArray['effects'][] = trim($subset);
305
+ }
306
+ } else {
307
+ // Only one subset
308
+ $fontsArray['effects'][] = $fontQueries['effect'];
309
+ }
310
+ }
311
+ }
312
+
313
+ if (! empty($fontsArray)) {
314
+ $finalCombinedParameters = '';
315
+ ksort($fontsArray['families']);
316
+
317
+ // Families
318
+ foreach ($fontsArray['families'] as $familyRaw => $fontValues) {
319
+ $finalCombinedParameters .= str_replace(' ', '+', $familyRaw);
320
+
321
+ // Any types? e.g. 400, 400italic, bold, etc.
322
+ if (isset($fontValues['types']) && is_array($fontValues['types']) && ! empty($fontValues['types'])) {
323
+ $finalCombinedParameters .= ':'.implode(',', $fontValues['types']);
324
+ }
325
+
326
+ $finalCombinedParameters .= '|';
327
+ }
328
+
329
+ $finalCombinedParameters = trim($finalCombinedParameters, '|');
330
+
331
+ // Subsets
332
+ if (isset($fontsArray['subsets']) && ! empty($fontsArray['subsets'])) {
333
+ sort($fontsArray['subsets']);
334
+ $finalCombinedParameters .= '&subset='.implode(',', array_unique($fontsArray['subsets']));
335
+ }
336
+
337
+ // Effects
338
+ if (isset($fontsArray['effects']) && ! empty($fontsArray['effects'])) {
339
+ sort($fontsArray['effects']);
340
+ $finalCombinedParameters .= '&effect='.implode('|', array_unique($fontsArray['effects']));
341
+ }
342
+
343
+ if ($fontDisplay = Main::instance()->settings['google_fonts_display']) {
344
+ $finalCombinedParameters .= '&display='.$fontDisplay;
345
+ }
346
+
347
+ $finalCombinedParameters = esc_attr($finalCombinedParameters);
348
+
349
+ $finalCombinedLink = <<<HTML
350
+ <link rel='stylesheet' id='wpacu-combined-google-fonts-css' href='https://fonts.googleapis.com/css?family={$finalCombinedParameters}' type='text/css' media='all' />
351
+ HTML;
352
+ $finalCombinedLink .= "\n";
353
+
354
+ $htmlSource = str_replace(self::COMBINED_LINK_DEL, apply_filters('wpacu_combined_google_fonts_link_tag', $finalCombinedLink), $htmlSource);
355
+ }
356
+
357
+ return $htmlSource;
358
+ }
359
+ }
classes/OptimiseAssets/MinifyCss.php CHANGED
@@ -278,6 +278,9 @@ class MinifyCss
278
279
$cssContent = OptimizeCss::maybeFixCssBackgroundUrls($cssContent, $pathToAssetDir . '/'); // Minify it and save it to /wp-content/cache/css/min/
280
281
$cssContent = self::applyMinification($cssContent);
282
283
// Relative path to the new file
278
279
$cssContent = OptimizeCss::maybeFixCssBackgroundUrls($cssContent, $pathToAssetDir . '/'); // Minify it and save it to /wp-content/cache/css/min/
280
281
+ // Any "font-display" enabled in "Settings" - "Google Fonts"?
282
+ $cssContent = GoogleFonts::alterGoogleFontUrlFromCssContent($cssContent);
283
+
284
$cssContent = self::applyMinification($cssContent);
285
286
// Relative path to the new file
classes/OptimiseAssets/OptimizeCss.php CHANGED
@@ -237,7 +237,7 @@ class OptimizeCss
237
$finalTagUrl = OptimizeCommon::filterWpContentUrl() . self::getRelPathCssCacheDir() . $storageJsonContentLocation['uri_to_final_css_file'];
238
239
$finalCssTag = <<<HTML
240
- <link id='asset-cleanup-combined-css-{$locationTag}' rel='stylesheet' href='{$finalTagUrl}' type='text/css' media='all' />
241
HTML;
242
243
$htmlSourceBeforeAnyLinkTagReplacement = $htmlSource;
237
$finalTagUrl = OptimizeCommon::filterWpContentUrl() . self::getRelPathCssCacheDir() . $storageJsonContentLocation['uri_to_final_css_file'];
238
239
$finalCssTag = <<<HTML
240
+ <link id='wpacu-combined-css-{$locationTag}' rel='stylesheet' href='{$finalTagUrl}' type='text/css' media='all' />
241
HTML;
242
243
$htmlSourceBeforeAnyLinkTagReplacement = $htmlSource;
classes/OptimiseAssets/OptimizeJs.php CHANGED
@@ -326,7 +326,7 @@ class OptimizeJs
326
$deferAttr = (isset($cachedValues['extras']) && in_array('defer', $cachedValues['extras'])) ? 'defer="defer"' : '';
327
328
$finalJsTag = <<<HTML
329
- <script {$deferAttr} id='asset-cleanup-combined-js-group-{$groupNo}' type='text/javascript' src='{$finalTagUrl}'></script>
330
HTML;
331
$tagsStripped = 0;
332
326
$deferAttr = (isset($cachedValues['extras']) && in_array('defer', $cachedValues['extras'])) ? 'defer="defer"' : '';
327
328
$finalJsTag = <<<HTML
329
+ <script {$deferAttr} id='wpacu-combined-js-group-{$groupNo}' type='text/javascript' src='{$finalTagUrl}'></script>
330
HTML;
331
$tagsStripped = 0;
332
classes/Preloads.php CHANGED
@@ -277,11 +277,11 @@ class Preloads
277
{
278
if (Misc::wpfcMinifyCssEnabledOnly()) {
279
// [wpacu_lite]
280
- return '<link rel=\'preload\' data-from-rel=\'stylesheet\' as=\'style\' href=\'' . $linkHref . '\' data-asset-cleanup-preload-css-basic=\'1\' />' . "\n";
281
// [/wpacu_lite]
282
}
283
284
- return '<link rel=\'preload\' as=\'style\' href=\''.$linkHref.'\' data-asset-cleanup-preload-css-basic=\'1\' />'."\n";
285
}
286
287
/**
@@ -307,7 +307,7 @@ class Preloads
307
continue;
308
}
309
310
- $linkPreload = '<link rel=\'preload\' as=\'script\' href=\''.$scriptSrc.'\' data-asset-cleanup-preload-js=\'1\'>'."\n";
311
312
$htmlSource = str_replace(self::DEL_SCRIPTS_PRELOADS, $linkPreload . self::DEL_SCRIPTS_PRELOADS, $htmlSource);
313
}
277
{
278
if (Misc::wpfcMinifyCssEnabledOnly()) {
279
// [wpacu_lite]
280
+ return '<link rel=\'preload\' data-from-rel=\'stylesheet\' as=\'style\' href=\'' . $linkHref . '\' data-wpacu-preload-css-basic=\'1\' />' . "\n";
281
// [/wpacu_lite]
282
}
283
284
+ return '<link rel=\'preload\' as=\'style\' href=\''.$linkHref.'\' data-wpacu-preload-css-basic=\'1\' />'."\n";
285
}
286
287
/**
307
continue;
308
}
309
310
+ $linkPreload = '<link rel=\'preload\' as=\'script\' href=\''.$scriptSrc.'\' data-wpacu-preload-js=\'1\'>'."\n";
311
312
$htmlSource = str_replace(self::DEL_SCRIPTS_PRELOADS, $linkPreload . self::DEL_SCRIPTS_PRELOADS, $htmlSource);
313
}
classes/Settings.php CHANGED
@@ -92,7 +92,13 @@ class Settings
92
'allow_usage_tracking',
93
94
// Clear Cached CSS/JS files after (x) days
95
- 'clear_cached_files_after'
96
);
97
98
/**
92
'allow_usage_tracking',
93
94
// Clear Cached CSS/JS files after (x) days
95
+ 'clear_cached_files_after',
96
+
97
+ // Google Fonts: Combine Into One Request
98
+ 'google_fonts_combine',
99
+
100
+ // Google Fonts: "display" CSS property
101
+ 'google_fonts_display'
102
);
103
104
/**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: pagespeed, page speed, dequeue, minify css, performance
4
Donate link: https://gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
5
Requires at least: 4.4
6
Tested up to: 5.2.2
7
- Stable tag: 1.3.3.5
8
License: GPLv3
9
License URI: http://www.gnu.org/licenses/gpl.html
10
@@ -157,6 +157,9 @@ With the recently released "Test Mode" feature, you can safely unload assets on
157
4. Homepage CSS & JS Management (List sorted by location)
158
159
== Changelog ==
160
= 1.3.3.5 =
161
* New Option To Conveniently Site-Wide Unload Gutenberg CSS Library Block in "Settings" -> "Site-Wide Common Unloads"
162
* Better way to clear cached files as the system doesn't just check the version number of the enqueued file, but also the contents of the file in case an update is made for a CSS/JS file on the server, and the developer(s) forgot to update the version number
4
Donate link: https://gabelivan.com/items/wp-asset-cleanup-pro/?utm_source=wp_org_lite&utm_medium=donate
5
Requires at least: 4.4
6
Tested up to: 5.2.2
7
+ Stable tag: 1.3.3.6
8
License: GPLv3
9
License URI: http://www.gnu.org/licenses/gpl.html
10
157
4. Homepage CSS & JS Management (List sorted by location)
158
159
== Changelog ==
160
+ = 1.3.3.6 =
161
+ * New Feature: Google Fonts Optimization: Combine multiple font requests into fewer requests; Option to add "font-display" CSS property (PageSpeed Insights Reference: "Ensure text remains visible during webfont load")
162
+
163
= 1.3.3.5 =
164
* New Option To Conveniently Site-Wide Unload Gutenberg CSS Library Block in "Settings" -> "Site-Wide Common Unloads"
165
* Better way to clear cached files as the system doesn't just check the version number of the enqueued file, but also the contents of the file in case an update is made for a CSS/JS file on the server, and the developer(s) forgot to update the version number
templates/_admin-page-settings-plugin-areas/_google-fonts.php ADDED
@@ -0,0 +1,109 @@
1
+ <?php
2
+ /*
3
+ * No direct access to this file
4
+ */
5
+ if (! isset($data)) {
6
+ exit;
7
+ }
8
+
9
+ if (! defined('WPACU_USE_MODAL_BOX')) {
10
+ define('WPACU_USE_MODAL_BOX', true);
11
+ }
12
+
13
+ $tabIdArea = 'wpacu-setting-google-fonts';
14
+ $styleTabContent = ($selectedTabArea === $tabIdArea) ? 'style="display: table-cell;"' : '';
15
+
16
+ $ddOptions = array(
17
+ 'swap' => 'swap (most used)',
18
+ 'auto' => 'auto',
19
+ 'block' => 'block',
20
+ 'fallback' => 'fallback',
21
+ 'optional' => 'optional'
22
+ );
23
+ ?>
24
+ <div id="<?php echo $tabIdArea; ?>" class="wpacu-settings-tab-content" <?php echo $styleTabContent; ?>>
25
+ <h2 class="wpacu-settings-area-title"><?php _e('Google Fonts: Load Optimizer', 'wp-asset-clean-up'); ?></h2>
26
+ <table class="wpacu-form-table">
27
+ <tr valign="top">
28
+ <th scope="row" class="setting_title">
29
+ <label for="wpacu_google_fonts_combine"><?php _e('Combine Multiple Requests Into Fewer Ones', 'wp-asset-clean-up'); ?></label>
30
+ </th>
31
+ <td>
32
+ <label class="wpacu_switch">
33
+ <input id="wpacu_google_fonts_combine"
34
+ type="checkbox"
35
+ <?php echo (($data['google_fonts_combine'] == 1) ? 'checked="checked"' : ''); ?>
36
+ name="<?php echo WPACU_PLUGIN_ID . '_settings'; ?>[google_fonts_combine]"
37
+ value="1" /> <span class="wpacu_slider wpacu_round"></span> </label>
38
+
39
+ &nbsp;<?php _e('This option combines multiple font requests into fewer requests', 'wp-asset-clean-up'); ?>
40
+ <p><strong>Example</strong> The following LINK tags will be merged into one tag:</p>
41
+
42
+ <ul>
43
+ <li><code>&lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine:italic"&gt;</code></li>
44
+ <li><code>&lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata:bold"&gt;</code></li>
45
+ <li><code>&lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono"&gt;</code></li>
46
+ </ul>
47
+ <hr />
48
+ <ul>
49
+ <li><code>&lt;link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine:italic|Inconsolata:bold|Roboto+Mono"&gt;</code></li>
50
+ </ul>
51
+
52
+ <p><strong>Result:</strong> This simple feature saves one round trip to the server for each additional font requested (reducing the number of HTTP requests), and also protects against blocking on older browsers which only have 2 connections open per domain at a time.</p>
53
+ </td>
54
+ </tr>
55
+ <tr valign="top">
56
+ <th scope="row" class="setting_title">
57
+ <?php echo sprintf(__('Apply %s CSS property value', 'wp-asset-clean-up'), '<span style="background: #f5f5f5; padding: 4px;">font-display:</span>'); ?>
58
+ </th>
59
+ <td>
60
+ <select name="<?php echo WPACU_PLUGIN_ID . '_settings'; ?>[google_fonts_display]">
61
+ <option value="">[none set]</option>
62
+ <?php
63
+ foreach ($ddOptions as $ddOptionValue => $ddOptionText) {
64
+ $selectedOption = ($data['google_fonts_display'] === $ddOptionValue) ? 'selected="selected"' : '';
65
+ echo '<option '.$selectedOption.' value="'.$ddOptionValue.'">'.$ddOptionText.'</option>'."\n";
66
+ }
67
+ ?>
68
+ </select>
69
+ &nbsp;
70
+ <?php _e('This feature applies site-wide "&display=" with the chosen value to all the Google Font URL requests (if the parameter is not already set in the URL).', 'wp-asset-clean-up'); ?>
71
+ <?php _e('This will result in printing of "font-display" CSS property within @font-face.', 'wp-asset-clean-up'); ?>
72
+ <span style="color: #0073aa;" class="dashicons dashicons-info"></span> <a id="wpacu-google-fonts-display-info-target" href="#wpacu-google-fonts-display-info"><?php _e('Read more', 'wp-asset-clean-up'); ?></a>
73
+
74
+ <hr />
75
+
76
+ <p><?php echo __('Deciding the behavior for a web font as it is loading can be an important performance tuning technique. If applied, this option ensures text remains visible during webfont load.', 'wp-asset-clean-up'); ?> <?php _e('The <code>font-display</code> CSS property defines how font files are loaded and display by the browser.', 'wp-asset-clean-up'); ?></p>
77
+
78
+ <strong>Read more about this:</strong>
79
+ <ul style="margin-top: 5px;">
80
+ <li>- <a target="_blank" href="https://css-tricks.com/hey-hey-font-display/">Hey hey `font-display`</a></li>
81
+ <li>- <a target="_blank" href="https://css-tricks.com/font-display-masses/">`font-display` for the Masses</a></li>
82
+ <li>- <a target="_blank" href="https://developers.google.com/web/updates/2016/02/font-display">Controlling Font Performance with font-display</a></li>
83
+ <li>- <a target="_blank" href="https://font-display.glitch.me/">https://font-display.glitch.me/</a></li>
84
+ <li>- <a target="_blank" href="https://vimeo.com/241111413">Video: Fontastic Web Performance</a></li>
85
+ </ul>
86
+ </td>
87
+ </tr>
88
+ </table>
89
+ </div>
90
+
91
+ <div id="wpacu-google-fonts-display-info" class="wpacu-modal" style="padding-top: 70px;">
92
+ <div class="wpacu-modal-content" style="max-width: 800px;">
93
+ <span class="wpacu-close">&times;</span>
94
+ <h3 style="margin-top: 2px; margin-bottom: 5px;">font-display: <span style="background: #f2faf2;">swap</span></h3>
95
+ <p style="margin-top: 0; margin-bottom: 24px;">The text is shown immediately (without any block period, no invisible text) in the fallback font until the custom font loads, then it's swapped with the custom font. You get a <strong>FOUT</strong> (<em>flash of unstyled text</em>).</p>
96
+
97
+ <h3 style="margin-bottom: 5px;">font-display: <span style="background: #f2faf2;">block</span></h3>
98
+ <p style="margin-top: 0; margin-bottom: 24px;">The text blocks (is invisible) for a short period. Then, if the custom font hasn't been downloaded yet, the browser swaps (renders the text in the fallback font), for however long it takes the custom font to be downloaded, and then re-renders the text in the custom font. You get a <strong>FOIT</strong> (<em>flash of invisible text</em>).</p>
99
+
100
+ <h3 style="margin-bottom: 5px;">font-display: <span style="background: #f2faf2;">fallback</span></h3>
101
+ <p style="margin-top: 0; margin-bottom: 24px;">This is somewhere in between block and swap. The text is invisible for a short period of time (100ms). Then if the custom font hasn't downloaded, the text is shown in a fallback font (for about 3s), then swapped after the custom font loads.</p>
102
+
103
+ <h3 style="margin-bottom: 5px;">font-display: <span style="background: #f2faf2;">optional</span></h3>
104
+ <p style="margin-top: 0; margin-bottom: 24px;">This behaves just like fallback, only the browser can decide to not use the custom font at all, based on the user's connection speed (if you're on a slow 3G or less, it will take forever to download the custom font and then swapping to it will be too late and extremely annoying)</p>
105
+
106
+ <h3 style="margin-bottom: 5px;">font-display: <span style="background: #f2faf2;">auto</span></h3>
107
+ <p style="margin-top: 0; margin-bottom: 0;">The default. Typical browser font loading behavior will take place. This behavior may be FOIT, or FOIT with a relatively long invisibility period. This may change as browser vendors decide on better default behaviors.</p>
108
+ </div>
109
+ </div>
templates/admin-page-settings-plugin.php CHANGED
@@ -30,6 +30,7 @@ if ($showSettingsType === 'tabs') {
30
'wpacu-setting-combine-loaded-files' => __( 'Combine CSS &amp; JS Files', 'wp-asset-clean-up' ),
31
'wpacu-setting-common-files-unload' => __( 'Site-Wide Common Unloads', 'wp-asset-clean-up' ),
32
'wpacu-setting-html-source-cleanup' => __( 'HTML Source CleanUp', 'wp-asset-clean-up' ),
33
'wpacu-setting-disable-xml-rpc' => __( 'Disable XML-RPC', 'wp-asset-clean-up' ),
34
);
35
@@ -74,6 +75,7 @@ if ($showSettingsType === 'tabs') {
74
include_once '_admin-page-settings-plugin-areas/_combine-loaded-files.php';
75
include_once '_admin-page-settings-plugin-areas/_common-files-unload.php';
76
include_once '_admin-page-settings-plugin-areas/_html-source-cleanup.php';
77
include_once '_admin-page-settings-plugin-areas/_disable-xml-rpc-protocol.php';
78
?>
79
30
'wpacu-setting-combine-loaded-files' => __( 'Combine CSS &amp; JS Files', 'wp-asset-clean-up' ),
31
'wpacu-setting-common-files-unload' => __( 'Site-Wide Common Unloads', 'wp-asset-clean-up' ),
32
'wpacu-setting-html-source-cleanup' => __( 'HTML Source CleanUp', 'wp-asset-clean-up' ),
33
+ 'wpacu-setting-google-fonts' => __( 'Google Fonts', 'wp-asset-clean-up' ),
34
'wpacu-setting-disable-xml-rpc' => __( 'Disable XML-RPC', 'wp-asset-clean-up' ),
35
);
36
75
include_once '_admin-page-settings-plugin-areas/_combine-loaded-files.php';
76
include_once '_admin-page-settings-plugin-areas/_common-files-unload.php';
77
include_once '_admin-page-settings-plugin-areas/_html-source-cleanup.php';
78
+ include_once '_admin-page-settings-plugin-areas/_google-fonts.php';
79
include_once '_admin-page-settings-plugin-areas/_disable-xml-rpc-protocol.php';
80
?>
81
templates/meta-box-loaded-assets/_asset-style-single-row.php CHANGED
@@ -55,12 +55,23 @@ sort($childHandles);
55
$data['row']['obj']->preload_status = 'not_preloaded'; // default
56
57
if (isset($data['row']['obj']->src, $data['row']['obj']->srcHref) && $data['row']['obj']->src && $data['row']['obj']->srcHref) {
58
$relSrc = str_replace(site_url(), '', $data['row']['obj']->src);
59
60
if (isset($data['row']['obj']->baseUrl)) {
61
$relSrc = str_replace($data['row']['obj']->baseUrl, '/', $data['row']['obj']->src);
62
}
63
64
$appendAfterSrcHref = (strpos($data['row']['obj']->srcHref, '?') === false) ? '?' : '&';
65
66
$isCssPreload = (isset($data['preloads']['styles'][$data['row']['obj']->handle]) && $data['preloads']['styles'][$data['row']['obj']->handle])
55
$data['row']['obj']->preload_status = 'not_preloaded'; // default
56
57
if (isset($data['row']['obj']->src, $data['row']['obj']->srcHref) && $data['row']['obj']->src && $data['row']['obj']->srcHref) {
58
+ // Formatting for Google Fonts
59
+ $data['row']['obj']->src = urldecode(\WpAssetCleanUp\OptimiseAssets\GoogleFonts::alterGoogleFontLink($data['row']['obj']->src));
60
+ $data['row']['obj']->src = str_replace(' ', '+', $data['row']['obj']->src);
61
+
62
+ $data['row']['obj']->srcHref = urldecode(\WpAssetCleanUp\OptimiseAssets\GoogleFonts::alterGoogleFontLink($data['row']['obj']->srcHref));
63
+ $data['row']['obj']->srcHref = str_replace(' ', '+', $data['row']['obj']->srcHref);
64
+
65
$relSrc = str_replace(site_url(), '', $data['row']['obj']->src);
66
67
if (isset($data['row']['obj']->baseUrl)) {
68
$relSrc = str_replace($data['row']['obj']->baseUrl, '/', $data['row']['obj']->src);
69
}
70
71
+ // "font-display" CSS Property for Google Fonts - underline the URL parameter
72
+ $toUnderline = 'display='.$data['plugin_settings']['google_fonts_display'];
73
+ $relSrc = str_replace($toUnderline, '<u style="background: #f2faf2;">'.$toUnderline.'</u>', $relSrc);
74
+
75
$appendAfterSrcHref = (strpos($data['row']['obj']->srcHref, '?') === false) ? '?' : '&';
76
77
$isCssPreload = (isset($data['preloads']['styles'][$data['row']['obj']->handle]) && $data['preloads']['styles'][$data['row']['obj']->handle])
wpacu-load.php CHANGED
@@ -105,4 +105,7 @@ if (is_admin()) {
105
*/
106
$wpacuCleanUp = new \WpAssetCleanUp\CleanUp();
107
$wpacuCleanUp->init();
108
}
105
*/
106
$wpacuCleanUp = new \WpAssetCleanUp\CleanUp();
107
$wpacuCleanUp->init();
108
+
109
+ $wpacuGoogleFonts = new \WpAssetCleanUp\OptimiseAssets\GoogleFonts();
110
+ $wpacuGoogleFonts->init();
111
}
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.3.5
6
* Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
7
* Author: Gabriel Livan
8
* Author URI: http://gabelivan.com/
@@ -12,7 +12,7 @@
12
13
// Is the Pro version triggered before the Lite one and are both plugins active?
14
if (! defined('WPACU_PLUGIN_VERSION')) {
15
- define('WPACU_PLUGIN_VERSION', '1.3.3.5');
16
}
17
18
// 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.3.6
6
* Description: Unload Chosen Scripts & Styles from Posts/Pages to reduce HTTP Requests, Combine/Minify CSS/JS files
7
* Author: Gabriel Livan
8
* Author URI: http://gabelivan.com/
12
13
// Is the Pro version triggered before the Lite one and are both plugins active?
14
if (! defined('WPACU_PLUGIN_VERSION')) {
15
+ define('WPACU_PLUGIN_VERSION', '1.3.3.6');
16
}
17
18
// Exit if accessed directly