Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #7284: Preload Fonts - Filter to add extensions #7318

Open
wants to merge 22 commits into
base: feature/3.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions inc/Engine/Media/PreloadFonts/Frontend/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,23 @@ public function add_custom_data( array $data ): array {
*/
$font_data = wpm_apply_filters_typed( 'array', 'rocket_preload_fonts_font_data', [] );

$processed_extensions = [
'woff2',
'woff',
'ttf',
];

/**
* Filters the list of processed font extensions.
*
* @param array $processed_extensions Array of processed font extensions.
*/
$processed_extensions = wpm_apply_filters_typed( 'array', 'rocket_preload_fonts_processed_extensions', $processed_extensions );

$data['system_fonts'] = $system_fonts;
$data['font_data'] = $font_data;
$data['status']['preload_fonts'] = $this->context->is_allowed();
$data['processed_extensions'] = $processed_extensions;

return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
use WP_Rocket\Engine\Optimization\LazyRenderContent\ServiceProvider as LRCServiceProvider;
use WP_Rocket\Engine\Media\Fonts\ServiceProvider as MediaFontsServiceProvider;
use WP_Rocket\Engine\Media\PreloadFonts\ServiceProvider as PreloadFontsServiceProvider;

use WP_Rocket\Engine\Media\PreconnectExternalDomains\ServiceProvider as PreconnectExternalDomainsServiceProvider;

/**
* Plugin Manager.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<html>
<head>
<title>Test</title>
<title>
Test</title>
</head>
<body>
</html>
<script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<html>
<head>
<title>Test</title>
<title>
Test</title>
</head>
<body>
<iframe srcdoc="
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Iframe Content</title>
</head>
<body>
<header>
<h1>Iframe Header</h1>
</header>
</body>
</html>
" width="600" height="400" style="border:none;"></iframe>
<script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<iframe srcdoc="<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>
Iframe Content</title>
</head>
<body>
<header>
<h1>
Iframe Header</h1>
</header>
</body>
</html>
" width="600" height="400" style="border:none;">
</iframe>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<html>
<head>
<title>Test</title>
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="http://example.org/assets/fonts/font1.woff2">
<link rel="stylesheet" href="http://example.org/assets/fonts/font2.ttf">
</head>
<body><script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<head>
<title>
Test</title>
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="http://example.org/assets/fonts/font1.woff2">
<link rel="stylesheet" href="http://example.org/assets/fonts/font2.ttf">
</head>
<body>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<html>
<head>
<title>Test</title>
<link crossorigin data-rocket-preload as="font" href="http://external.domain/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="http://external.domain/assets/fonts/font1.woff2">
<link rel="stylesheet" href="http://example.org/assets/fonts/font2.ttf">
</head>
<body><script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<head>
<title>
Test</title>
<link crossorigin data-rocket-preload as="font" href="http://external.domain/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="http://example.org/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="http://external.domain/assets/fonts/font1.woff2">
<link rel="stylesheet" href="http://example.org/assets/fonts/font2.ttf">
</head>
<body>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<html>
<head>
<title>Test</title>
<link data-rocket-preload as="font" href="/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="/assets/fonts/font1.woff2">
<link rel="stylesheet" href="/assets/fonts/font2.ttf">
</head>
<body><script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<head>
<title>
Test</title>
<link data-rocket-preload as="font" href="/assets/fonts/font1.woff2" rel="preload">
<link data-rocket-preload as="font" href="/assets/fonts/font2.ttf" rel="preload">
<link rel="stylesheet" href="/assets/fonts/font1.woff2">
<link rel="stylesheet" href="/assets/fonts/font2.ttf">
</head>
<body>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<html>
<head>
<title>Test</title>
<title>
Test</title>
</head>
<body>
<script>var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script><script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async></script></body>
<script>
var rocket_beacon_data = {"ajax_url":"http:\/\/example.org\/wp-admin\/admin-ajax.php","nonce":"96ac96b69e","url":"http:\/\/example.org","is_mobile":false,"width_threshold":1600,"height_threshold":700,"delay":500,"debug":false,"status":{"atf":true,"lrc":true,"preload_fonts":true,"preconnect_external_domain":true},"elements":"img, video, picture, p, main, div, li, svg, section, header, span","lrc_threshold":1800,"system_fonts":["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","Arial","Helvetica","Times New Roman","Times","Courier New","Courier","Georgia","Palatino","Garamond","Bookman","Tahoma","Trebuchet MS","Arial Black","Impact","Comic Sans MS"],"font_data":[],"processed_extensions":["woff2","woff","ttf"],"preconnect_external_domain_elements":["link","script","iframe"],"preconnect_external_domain_exclusions":[{"type":"attribute","key":"rel","value":"profile"},{"type":"attribute","key":"rel","value":"preconnect"},{"type":"attribute","key":"rel","value":"dns-prefetch"},{"type":"attribute","key":"async","value":""},{"type":"domain","value":"static.cloudflareinsights.com"}]}</script>
<script data-name="wpr-wpr-beacon" src='http://example.org/wp-content/plugins/wp-rocket/assets/js/wpr-beacon.min.js' async>
</script>
</body>
</html>
Loading
Loading