Title: Defer non-essential javascript issue
Last modified: January 9, 2024

---

# Defer non-essential javascript issue

 *  Resolved [mikeeddie](https://wordpress.org/support/users/mikeeddie/)
 * (@mikeeddie)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/)
 * 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:
 *     ```wp-block-code
       	$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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdefer-non-essential-javascript-issue%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Dan (a11n)](https://wordpress.org/support/users/drawmyface/)
 * (@drawmyface)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17365694)
 * 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](https://jetpack.com/support/jetpack-boost/#frequently-asked-questions),
   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)](https://wordpress.org/support/users/erania-pinnera/)
 * (@erania-pinnera)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17386334)
 * Hi [@mikeeddie](https://wordpress.org/support/users/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](https://wordpress.org/support/users/mikeeddie/)
 * (@mikeeddie)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17389142)
 * 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
 *     ```wp-block-code
       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 2 years, 4 months ago by [mikeeddie](https://wordpress.org/support/users/mikeeddie/).
 *  Plugin Support [Alin (a11n)](https://wordpress.org/support/users/alinclamba/)
 * (@alinclamba)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17398622)
 * Hi [@mikeeddie](https://wordpress.org/support/users/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)](https://wordpress.org/support/users/erania-pinnera/)
 * (@erania-pinnera)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17420488)
 * Hello [@mikeeddie](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/jetpack-boost/assets/icon.svg?rev=2818794)
 * [Jetpack Boost - Website Speed, Performance and Critical CSS](https://wordpress.org/plugins/jetpack-boost/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack-boost/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack-boost/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack-boost/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack-boost/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack-boost/reviews/)

 * 5 replies
 * 4 participants
 * Last reply from: [Stef (a11n)](https://wordpress.org/support/users/erania-pinnera/)
 * Last activity: [2 years, 3 months ago](https://wordpress.org/support/topic/defer-non-essential-javascript-issue/#post-17420488)
 * Status: resolved