Putting JavaScript at the end of the page results in an error

I recently read that for faster webpage loading, it is good practice to put JavaScript links at the end. I did, but now the link file functions are not working. If I put the link at the top of the page, everything will be fine.

Is this thing to install javascript at the end of the job only under certain circumstances?

+3
source share
3 answers

I also went through testing. If you download a Javascript file, it’s faster to put it at the end, but it contains some important caveats.

-, . , jQuery , , . , , , , .

-, , , . :

$(function() {
  // ...
});

, , jQuery. , .

, , . , , , Javascript, . , , Javascript 50-200 .

, ( ) Javascript, Javascript, . , ( , ), .

, , Javascript .

+5

, , JQuery, . .JS, , , , Jquery- .

JQ css, Javascript - . Javascript

+2

Yahoo YUI, , JavaScript . ,

It appears that Yahoo Practice is roughly "the library code at the beginning of <body>, the active code at the end of <body>."

Beware, however, this can lead to Flash of Unstyled Content Syndrome .

+1
source

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


All Articles