Tagged: Bugs
-
3.1.1 HTTPS Fonts and Blocking Fonts
-
August 24, 2016 at 10:05 pm #9855
Please see next post
August 24, 2016 at 10:05 pm #9857This reply has been marked as private.August 25, 2016 at 8:04 pm #98851- Regarding Google Fonts Blocking issue, Up till now we didn’t find a solution that is free of problems, the link that you shared offers webfonts.js, it loads the font async and removes the error from google page speed however it flashes the font since it loads it randomly in the footer
– If we add the font in the header and async the error is not removed from google, it still sees the font as a blocker
Anyway till we find a fix for it please add this function to your child theme
add_action( 'wp_footer', 'circleflip_get_google_fonts' ); /* Enque Script of Google Fonts */ if ( ! function_exists( 'circleflip_get_google_fonts' ) ) : function circleflip_get_google_fonts() { $link = ''; $googleFonts = ''; $my_fonts = array( 'BebasNeueRegular' => 'BebasNeueRegular', 'Times New Roman' => 'Times New Roman', 'Arial' => 'Arial', 'DroidArabicKufi' => 'DroidArabicKufi', 'SourceSansSemiBold' => 'SourceSansSemiBold', 'sourceSans' => 'sourceSans', 'Helvetica' => 'Helvetica', 'museo_slab500' => 'museo_slab500' ); $cfOptions = get_option( 'rojo', array() ); $faces = array(); foreach ( new RecursiveIteratorIterator( new RecursiveArrayIterator( $cfOptions ), RecursiveIteratorIterator::LEAVES_ONLY ) as $k => $value ) { if ( 'face' === $k ) { if ( ! in_array( $value, $my_fonts ) ) { $faces[] = $value; } } } $faces = array_unique( $faces ); $result = array_merge($faces, cr_get_option( 'cust_font',array() )); $result = array_unique($result); $googleFonts = implode ( '|' , $result); if ( $googleFonts != '' ) { // $link = 'https://fonts.googleapis.com/css?family=' . preg_replace( "/ /", "+", $googleFonts ); // wp_register_style( 'google_fonts', $link ); // wp_enqueue_style( 'google_fonts' ); ?> <script type="text/javascript"> WebFontConfig = { google: { families: [ '<?php echo $googleFonts;?>' ] } }; (function() { var wf = document.createElement('script'); // wf.src = '<?php echo get_template_directory_uri(); ?>/js/webfont.js'; wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'; wf.type = 'text/javascript'; wf.async = 'true'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wf, s); // WebFont.load(WebFontConfig); })(); </script> <?php } } endif;
and it should work but with the flashing effect of the font which we can’t find a proper solution for.
Regarding the mixed content:
We fixed the font issue and will be released in the next version
Best Regards
August 25, 2016 at 9:04 pm #9890Thanks!
August 25, 2016 at 10:54 pm #9891Here’s the article describing how to prevent the font refresh flicker.
August 25, 2016 at 10:59 pm #9892August 25, 2016 at 11:19 pm #9893The solution would be simply to hide everything in the body while fonts are loading and then set visibility once they are done using methodology above.
.wf-loading h1 {
/* styles to use while Typekit is loading */
}.wf-active h1 {
/* styles to use after Typekit is loaded */
}August 28, 2016 at 8:16 pm #9908Hi @karelleninc,
Unfortunately we can’t add this css to the core theme,
Please feel free to add it to style.css in your child-theme and for the script mentioned in the article you can add it in the functions.php of the child-theme in an early action like “init”
Let me know if you need anything else regarding this issue
Best Regards
August 28, 2016 at 8:26 pm #9910Yes, wf-inactive is available because of the code we sent you “dynamic font loading code – webfonts” and we won’t release this code to the public, so nobody will have wf-inactive class
Hope this helps
August 28, 2016 at 8:27 pm #9911I see, ok, thanks, I guess I’ll have to integrate it by myself.
Just curious, why would you not integrate dynamic font loading for everybody?
August 28, 2016 at 9:27 pm #9912Because it generates another issue which doesn’t have a clean solution, hiding elements and showing them after a font is loaded is a hack and not a solution
August 28, 2016 at 9:31 pm #9914Actually, it’s the official *solution* that stated by both TypeKit and Adobe for FOUT (flash of unstyled text) – https://github.com/typekit/webfontloader
You hide the rendering of the page while the fonts are not available (i.e. by default) and then switch visibility once. This prevents the page layout oscillation and flicker.
August 28, 2016 at 9:36 pm #9915Then i see it as a hack that is posted by TypeKit and Adobe, You can use it in your child theme easily so i guess there is no problem here
August 28, 2016 at 11:03 pm #9919@bassam 🙂 This how DOM works. Even if you Shadow DOM, changing the fonts will cause re-rendering of the entire layout. Either the fonts have to be blocking (causing delay in page building) or you have to allow the page to build asynchronously but render it several times as components are loaded. The latter will cause the FOUT, unless you hide it. I don’t see how any of it is a hack, since that’s how the browser rendering engine is supposed to operate under DOM/CSSOM rendering pipeline.
-
The topic ‘3.1.1 HTTPS Fonts and Blocking Fonts’ is closed to new replies.