If the Javascript code block is not at the end of the HTML file but uses jQuery $ (document) .ready (function () {...}), will this slow down the page display?

They say that Javascript code should be placed at the end of the HTML file, so the contents of the page are displayed first so that the user can see something (so that the user is happy to see something and not wait another 12 seconds, for example).

But in order to better encapsulate HTML and match Javascript code such as Image Carousel, usually HTML and Javascript are put in the same file, so there are blocks of JavaScript code, all mixed with HTML code during the final HTML file.

But what if all of these blocks of Javascript code use jQuery $(document).ready(function() { ... })to complete the task, will the page display not be too fast? I think that it’s not as fast as when Javascript is actually placed at the end of the HTML file, but close enough because it simply adds the function to the finished event queue.

+3
source share
1 answer

I think you need to place js at the bottom of the page (usually only inside the closing tag </body>) so that the content of the page is displayed during js loading.

jQuery, HTML .ready(), , , <body> . , , javascript HTML?

, , script. , .

, , .

javascript HTML . , / , script. , .

, .ready() , jQuery, , , , .

, , . , , js . js HTML, .

+2

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


All Articles