I'm struggling to see how either option would work - but happy to learn please...
Surely $CFG->wwwroot . 'http://code.jquery.com/jquery-3.2.1.min.js' just concatenates the moodle site wwwroot and the external url and gives a link that doesn't have any chance of working at all...
This is what I get on my local host if I add that line:
<script type="text/javascript" src="http://localhost/moodledevhttp://code.jquery.com/jquery-3.2.1.min.js"></script>So, there is no way it will work, whether in body or head.
Try taking out the $CFG->wwwroot . and see of it works then.