What is a good argument for / against using inline javascript inside the body html tag?

One of my employees thinks that it’s easier to just include the document.ready () (MULTIPLE) calls for jquery anywhere in the html document, instead of trying them all in the head, leg or in an external js file. Can you tell me about this?

Document.ready materials are loaded by modules that are included in the main template. I think this is dirty. But I need a good argument.

+3
source share
5 answers

There are a number of problems with your colleague:

  • This is not DRY. You must repeat the code every time you want to call it.
  • Javascript; .
  • , N .
  • , N .
+6

.

, ready() JS . 500-1000ms JS-, . JS . , . ( JS ).

, / , , (imho) .

- - , / , , . , , .

, , , , , /, . JS , , ?

, script, , . , .

+4

, , . , , , . Cuzillion, , .

+2

, javascript, (php, asp.net). , javascript . , javascript , .

+2

.

Javascript . Javascript </body>, . Google Analytics .

, , js. js , , . , Javascript, , Javascript , .

EDIT:

There are several ways to do what you do, I'm sure. And I do not know what you are doing. But since you mentioned Javascript next to each module, this gave me an idea. You can create a unique identifier for the div around each module. And then you can have a js file that performs operations on each module using this div id (via the jQuery selector). This would be a very convenient solution for jQuery.

+2
source

Source: https://habr.com/ru/post/1732107/


All Articles