Before you ask please READ THIS

Preloader stuck

Hi,

I have problem with preloader image. Sometime (First visit, clear website Data etc.) preloader stuck. In preloader settings try When DOM ready and second setting but same problem. I think it’s problem in some optimization setting in function.php Like this

// Async js
function async_parsing_of_js( $url ) {
if ( is_user_logged_in() ) return $url; //don't break WP Admin
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return str_replace( ' src', 'async src', $url );
}
add_filter( 'script_loader_tag', 'async_parsing_of_js', 10 );

// Remove type='text/javascript' and style
add_filter('style_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'codeless_remove_type_attr', 10, 2);
function codeless_remove_type_attr($tag, $handle) {
return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag );
}

Comments

  • edited December 2020 Posts: 115
    If stuck just reload page (sometimes 2-3 time) then site load correct

    1-st code is for async load js scripts except jquery
    2-nd code is for remove type from CSS and js
    https://codeless.co/remove-type-attribute-from-wordpress/
    Post edited by robi052 on
  • Posts: 115
    EDIT

    If change async with defer in frst code work fine, but is slower
  • AirAir
    Posts: 10,970
    Hey Robi :-)

    We have made safe optimizations that wouldn't conflict with anything.
    It is hard to say what your changes can make, as it requires some testing.

    Generally, we never use async, as this would fail much code that depends on the "ready" event of the JavaScript.

    With kind regards.
  • Posts: 115
    Thanks :smile:
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!