Add utility for async CSS loading pattern

This commit is contained in:
Tetrakern 2024-03-08 11:59:39 +01:00
parent f0612c7d0f
commit 07d076add7
2 changed files with 23 additions and 5 deletions

View File

@ -1266,11 +1266,7 @@ if ( ! function_exists( 'fictioneer_output_head_fonts' ) ) {
$bundled_fonts = WP_CONTENT_DIR . '/themes/fictioneer/cache/bundled-fonts.css';
$last_built_timestamp = get_option( 'fictioneer_bundled_fonts_timestamp', '123456789' );
$cache_bust = "?timestamp={$last_built_timestamp}";
$loading_pattern = '';
if ( FICTIONEER_ENABLE_ASYNC_ONLOAD_PATTERN ) {
$loading_pattern = 'media="print" onload="this.media=\'all\'; this.onload=null;"';
}
$loading_pattern = fictioneer_get_async_css_loading_pattern();
// Create file if it does not exist
if ( ! file_exists( $bundled_fonts ) ) {

View File

@ -2764,4 +2764,26 @@ function fictioneer_compare_wp_version( $version, $operator = '>=' ) {
return version_compare( $wp_version, $version, $operator );
}
// =============================================================================
// CSS LOADING PATTERN
// =============================================================================
if ( ! function_exists( 'fictioneer_get_async_css_loading_pattern' ) ) {
/**
* Returns the media attribute and loading strategy for stylesheets
*
* @since 5.12.2
*
* @return string Media attribute script for stylesheet links.
*/
function fictioneer_get_async_css_loading_pattern() {
if ( FICTIONEER_ENABLE_ASYNC_ONLOAD_PATTERN ) {
return 'media="print" onload="this.media=\'all\'; this.onload=null;"';
}
return 'media="all"';
}
}
?>