Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Safely moving jQuery to the footer

edited November 2017 in News & Announcements

I want to insert jQuery in the footer instead of the header for performance gains and best practice.

<?php echo js('jquery-3.2.1.min').js($js); ?>

However, I get a least one complaint (found so far), is there an easy for the above console error?

comment_reply.js?c=:1 Uncaught ReferenceError: $ is not defined


  • edited 8:12PM
    There is a line (26) of code in the views/themes/default/post.php that pulls in Javascript that will need to also be moved to the footer:
    <?=js('comment_reply', BLOG_FOLDER)?>
  • rl2rl2
    edited 8:12PM
    Yes, correct, I tried that...

    echo js('jquery-3.2.1.min').js($js);
    echo js('comment_reply').js($js);

    And got a complaint..

    Uncaught SyntaxError: Unexpected token < in comment_reply.js?c=:1
  • edited 8:12PM
    Are you able to use $ after you pull in jquery at all?
  • rl2rl2
    edited 8:12PM
    Yes, further in the footer.php I use many $ references.
  • edited 8:12PM
    Try this instead:
    <?=js('jquery-3.2.1.min').js($js)?> <?=js('comment_reply', BLOG_FOLDER)?>
  • rl2rl2
    edited 8:12PM
    Thanks, that's working now, it did indeed need the 2nd argument.
Sign In or Register to comment.