Okay
  Public Ticket #2145725
About Preload
Closed

Comments

  •  8
    ynskdemir started the conversation

    Hi, I want to preload this asset. Because it causes speed problem. Can you help?

    Attached files:  Adsız.jpg

  •  510
    Arlind replied

    Hi,

    The font is included in:

    assets/js/slick/slick-theme.css:16

    So the code to preload the font file is this:

    add_action( 'wp_head', function() {
        printf( '<link rel="preload" href="%s" as="font">', esc_attr( get_template_directory_uri() . '/assets/js/slick/fonts/slick.woff' ) );
    }, 1 );
    

    Kind regards,
    Arlind


      Documentation        Follow on Envato         Like on Facebook

  •  8
    ynskdemir replied

    If I place this code am I able to preload it? 

    Where should I place this code?

  •  510
    Arlind replied

    Hi,

    The code should be added in functions.php (end of file). I have modified to fix few missing attributes:

    add_action( 'wp_head', function() {
        printf( '<link rel="preload" href="%s" as="font" type="font/woff" crossorigin>', esc_attr( get_template_directory_uri() . '/assets/js/slick/fonts/slick.woff' ) );
    }, 1 );

    The browser will preload it automatically based on your question this is how preloading font works.

    Kind regards,
    Arlind


      Documentation        Follow on Envato         Like on Facebook

  •  8
    ynskdemir replied

    Thank you a lot :) It was very helpful