Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author David Clough

    (@cloughit)

    What plugin are you using to force the javascript into the footer?

    Thread Starter quikned

    (@quikned)

    I am using the Scripts-To-Footer plugin to get the scripts into the footer.

    https://wordpress.org/support/plugin/scripts-to-footerphp

    Plugin Author David Clough

    (@cloughit)

    Thanks, there lies your problem. The Scripts-To-Footer plugin uses a depreciated function wp_print_scripts rather than the correct function wp_enqueue_scripts to load the javascript files. You can see more info here: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_print_scripts

    Async Javascript hooks on to the wp_enqueue_scripts function to add async or defer.

    Thread Starter quikned

    (@quikned)

    I looked at the description of the plugin. It says…

    “This small plugin moves scripts to the footer. Note that this only works if you have plugins and a theme that utilizes wp_enqueue_scripts correctly.”

    So it seems like it uses wp_enqueue_scripts

    In any case, Do you recommend another plugin that properly moves the header scripts to the footer? One that you are compatible with?

    Plugin Author David Clough

    (@cloughit)

    Hi,

    I have just done some testing with Async Javascript and Scripts To Footer and on my test site the scripts are moved to the footer by Scripts To Footer and have Async or Defer added by Async Javascript.

    Further investigations of the code for Scripts To Footer tells me that the wp_print_scripts function is only being used for scripts which have been configured not to load in the footer. These scripts would be set using the options for the Scripts To Footer plugin. All scripts which have been enqueued using wp_enqueue_scripts are still loaded with wp_enqueue_scripts, only this happens in the fotter rather than the header.

    My suggestion would be:

    1. Check your settings for Scripts To Footer (Note: the checkboxes are to select conditions where the scripts SHOULD NOT be moved to the footer, so if you have any checked try unchecking them).
    2. Ensure that Async Javascript has been enabled and you have selected either Async or Defer.

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

The topic ‘'async' not being added to JS’ is closed to new replies.