• Resolved mikeeddie

    (@mikeeddie)


    Seems mostly everything works, but im running into one small but major issue for me. When I enable “defer non-essential javascript”, no_photo.gif fails to load….

    here is the snippet in the .php file:

    	$img_output = "<img onclick='window.location=\"".$link."\";' title='Parting Out ".$title."'onerror='ImgError(this, \"no_photo.gif\");' class='main_photo_img' src='";

    After doing some research, it seems that the script containing the ImgError function is being deferred before the image tries to load. From what I can gather, this timing issue can cause the function not to be available when the image fails to load, so its unable to produce “no_photo.gif”

    any work around?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Dan (a11n)

    (@drawmyface)

    Hi there,

    Thank you for providing the details about the issue you’re encountering with Jetpack Boost’s “defer non-essential javascript” feature and your website’s behavior, particularly concerning the loading of no_photo.gif.

    From your description, it seems that the ImgError function, which should handle the case when an image fails to load, is not available at the time it’s needed because the script containing this function is being deferred.

    One possible workaround would be to exclude that specific script from being deferred. For details of how to do that, please see our FAQ, specifically the section about How do I exclude some JavaScript files from being deferred?

    Please try excluding that script and test if the issue with the image loading persists.

    If you require further assistance or if this workaround does not resolve your issue, please reply in this thread with the outcomes and any additional details you can provide.

    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Hi @mikeeddie,

    Do you have updates about that? We usually close inactive threads after one week of no movement, but we want to make sure we’re all set before marking it as solved. Thanks!

    Thread Starter mikeeddie

    (@mikeeddie)

    Unfortunately no, I’ve tried replacing “here” in the code below with the enqueued .js file with no result, but I can confirm it is a defer script issue

    function wpdemo_enqueue_scripts() {
        wp_enqueue_script( 'HERE', get_template_directory_uri().'/js/wpdemo.js' );
    }
    add_action( 'wp_enqueue_scripts', 'wpdemo_enqueue_scripts' );
    function add_data_jetpack_boost_tag( $src, $handle ) {
        if ( $handle !== 'HERE') {
            return $src;
        }
        return str_replace( ' src', ' data-jetpack-boost="ignore" src', $src );
    }
    add_filter( 'script_loader_tag', 'add_data_jetpack_boost_tag', 10, 2 );
    • This reply was modified 9 months, 3 weeks ago by mikeeddie.
    Plugin Support Alin (a11n)

    (@alinclamba)

    Hi @mikeeddie,

    Sorry to hear the workaround didn’t pan out. It sounds like there’s a mismatch with the script handle or the way the exclusion is set up. Double-check the handle used in your wp_enqueue_script function matches exactly with what you’re specifying in the add_filter function.

    If you’re still stuck, could you share the exact name of the script handle you’re trying to exclude? Sometimes, a fresh pair of eyes can spot something you might have missed. We’re here to help you through this!

    Plugin Support Stef (a11n)

    (@erania-pinnera)

    Hello @mikeeddie,

    Do you have updates about that? We usually close inactive threads after one week of no movement, but we want to make sure we’re all set before marking it as solved. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Defer non-essential javascript issue’ is closed to new replies.