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