Safely moving jQuery to the footer
  • 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
  • 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)?>
  • 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
  • Are you able to use $ after you pull in jquery at all?
  • Yes, further in the footer.php I use many $ references.
  • Try this instead:

    <?=js('comment_reply', BLOG_FOLDER)?>
  • Thanks, that's working now, it did indeed need the 2nd argument.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!