Lord.

I listened to your ridicule and decided to understand the issue of creating and using JavaScript, I began to read the relevant literature, and then there was a discord in my head. In the book, Sir Flanigan writes that the script needs to be connected by reference, as expected, and its introduction to the page is very incorrect, but to learn more deeply, you need to shovel the n-th number of pages, and in order not to break the brain, I hasten to ask you like those who know and practice. To the question "google but not?" I will answer right away - I do not trust, anything can be written there, and they don’t have faith, but I don’t know more about accurate and reliable sources like you.

So, my familiar programmer took the script and shoved it into the widget located in the header. Yes, it works, yes, it rigidly animates, but it works.
Flanigan said, you need to connect via the head of reference. A programmer was taught 5 years. Question: who is right and what are the nuances?

  • And the right question, by the way. - VladD

3 answers 3

@ Nik555 wrote all right. But it is necessary to go also from a different plane.

Sir Flanigan is the person who wrote the book on JS, he knows how many difficulties the jumble of scripts creates in views, so he will initially do it and advise you to create a separate file with your own scripts for each page.

Currently, when developing any project, be it a business card site or a large portal, they try to make a beautiful and good frontend and connect various libraries and plugins for this, all this leads to the fact that your JS is not 2 lines.

Proceeding from what was written above, I would still trust Sir Flanigan and immediately create a separate file for JS, and your familiar programmer is simply lazy in terms of the frontend, like many programmers.

PS For those who believe that the new link is an extra request, I will answer immediately: minimizing, obfuscating and pasting JS will help you.

    If there is a lot of JS code, it is better to load it with a separate file, if you only need to write a couple of JS lines, then you can do without the file and just write it between the <script> tags.

      In my opinion, the right practice is to connect the script at the end of the document, and not in the header.