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

rl2rl2
edited November 2017 in News & Announcements
Hello,

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

Comments

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