Loading javascript once

My website (usphilatelics.com) had a large amount of javascript in header.php. I want to have this loaded into the footer, so have tried putting the script in a separate file, /sparkling-child/custom-js/vsb.js.
In functions.php I include the code :

function vsb_enqueue_scripts() {
    wp_enqueue_script( 'vsb', get_template_directory_uri() . '/sparkling-child/custom-js/vsb.js', array(), '', true ); 
}
add_action( 'wp_enqueue_scripts', 'vsb_enqueue_scripts' );

and in footer.php I include :

<?php wp_footer(); ?>
</body>
</html>

The result is that I get a ERR_CONTENT_DECODING_FAILED message. Where am I going wrong (I am new to this !) ?

Hi @blackjack,

I hope you are well today and thank you for your question.

Does that error disappear if you remove the above shared custom code added in the functions.php file?

Could you please share me your child theme where you are using this code so that i can troubleshoot it on my test site?

Alternatively you can try using the following solutions.

Best Regards,
Movin

Hi @Movin,
Thanks for the response. Yes the error message does disappear but of course then I do not have the javascript functions available.
The child theme’s footer.php is empty, the functions.php is :

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
    function chld_thm_cfg_parent_css() {
        wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'sparkling-bootstrap','sparkling-icons' ) );
    }
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );

// Enable shortcodes in text widgets
add_filter('widget_text','do_shortcode');

// END ENQUEUE PARENT ACTION

and the header.php, including the js script which I want to move to the footer, is attached.

I will study those links.

header included as a txt file

How do I get a copy of the header.php file to you ?

You can use any of the following plugins to download your whole child theme and share it to me.

Here you go …

I have tested your shared child theme on my test site but didn’t get any error message.

Could you please tell me exactly where you are getting the error ans share me the screenshot of it?

Also This can be due to plugin conflict on your site so please try temporary deactivating all plugins and see whether everything works fine and then enable the plugins one by one to see which plugin is conflicting if any.