JavaScript and CSS Order

I have an HTML file that is associated with a CSS file as well as a JavaScript file.

Is JavaScript executed and then CSS applied, or vice versa?

Can I reorder?

Thanks!

+4
source share
3 answers

JavaScript is executed when the <script> element is parsed. Some of the JSs may configure event handlers to trigger some JSs when events occur.

CSS applies to a live DOM. Changes to the DOM are automatically applied to CSS. Changes to CSS are applied to the entire DOM automatically.

+4
source

It is generally recommended that you import your scripts as soon as possible and your stylesheets as soon as possible. If possible, in fact, you should embed your entire script import at the very end of the <body> . I find this problematic when components that want to remove small script blocks that reference jQuery (for example) get to the page.

If your stylesheets are the first, this helps ensure that the browser applies styles before showing anything to the user. Conversely, by turning on the scripts for the last time, you put off this potentially slow processing of the script until the point where the user sees something on the screen.

+6
source

Yahoo’s research on speeding up page loading should be very helpful, and they explain things a lot more clearly than I can.

http://developer.yahoo.com/performance/rules.html

+2
source

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


All Articles