Site logo

[Support request] Can JQuery Move to Footer?

Home Forums Support [Support request] Can JQuery Move to Footer?

Home Forums Support Can JQuery Move to Footer?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1758100
    William

    Hello,

    I’m trying to optimize my site and one of the largest render blocking resources seems to be JQuery. If I move this to the footer, will it mess anything up on the theme?

    #1758133
    Leo
    Staff
    Customer Support

    Hi William,

    I don’t believe that’s a good idea.

    Looks like you are using the sticky navigation which is the only remaining option that uses jQuery.

    We are working on a solution to replace it with pure CS.

    As for now, I’d say that if you can live without it then that’s the way to go.

    Let me know if this helps 🙂

    #1758151
    William

    Thanks. Are there other options to not use a sticky navigation?

    #1758196
    Leo
    Staff
    Customer Support

    Sorry I’m not sure what you mean?

    We can already make the header fixed/stick with the CSS below. Just not possible with the hide when scrolling down option.

    .main-navigation {
        position: sticky;
        top: 0;
    }
    #1758216
    Alexander

    May I drop in with a solution?

    
    /*Move jQuery from Header to Footer*/
    add_action( 'wp_enqueue_scripts', 'jquery_in_footer' );
     function jquery_in_footer() {
     	wp_deregister_script( 'jquery' );
    	wp_register_script( 
    		'jquery', 
    		includes_url( '/js/jquery/jquery.js' ), 
    		false, // no dependencies
    		NULL, // no version to show
    		true // in footer? yes
    	);
    	wp_enqueue_script( 'jquery' );}
    #1758224
    Leo
    Staff
    Customer Support

    Thanks Alex!

    #1758227
    Alexander

    Really glad to help!

    #1758349
    William

    Sorry, I’m not super familiar with coding. When I said can I make it ‘not sticky’ I assumed that would remove the JQuery completely.

    Alex, which file do I add that to and does it need to be in any specific place?

    Thanks!

    #1758390
    Leo
    Staff
    Customer Support

    When I said can I make it ‘not sticky’ I assumed that would remove the JQuery completely.

    Yes that’s correct.

    Alex, which file do I add that to and does it need to be in any specific place?

    That code can be added with one of these methods:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.