JQuery Code in Header?

Of course I can add the code to a separate JS file, which I do. But again, this is bad practice too. But now in the other direction. If I only want to add code to one or some pages that doesn’t work (to my knowledge) because the JS file gets added to every page. So, you load code that’s not used (bad practice), which takes time, might cause problems etc.

a single custom.js is my approach. Definitely not a problem, because if you configured your hosting correctly is loaded only on the first page. And kept in memory until expires. Usually .js are not large files, so i think that's the best option. Much better than having to load code for every page. Especially under http 1.1.