The DOM: Style in the Header, Script in the Footer
The DOM: Style in the Header, Script in the Footer
Maybe you've been told that links to style sheets (CSS) should be included in the header and that links to script (JS) should be included in the footer. Ever asked yourself why?
If you've ever seen a webpage that loads the text first, then after a bit loads the formatting and style, you've seen a page that didn't have the links to style and script in the correct places.
This all has to do with how the browser decides it's loaded enough information to display. There's an event called 'DOMContentLoaded', and once that event happens, whatever is loaded will be displayed.
The DOM will tell the browser it's ready once the HTML is loaded, and sometimes the CSS and JS hasn't caught up. However, if you place the CSS in the header and the JS in the footer, you can ensure that all content will be loaded before the DOM triggers the 'DOMContentLoaded' event, the event that shows the user your content.
This is a simple explaination, as most of these videos are. For more information, I really liked this resource: http://ablogaboutcode.com/2011/06/14/how-javascript-loading-works-domcontentloaded-and-onload/
Other Videos By freeCodeCamp.org
2016-09-23 | Networks: Collision Detection and Avoidance |
2016-06-23 | Deploy a Dynamic Website in Minutes |
2016-06-23 | Gmail Keyboard Shortcuts |
2016-03-27 | Web Design: Development vs Design |
2016-03-27 | Computer Basics: What does 'Open Source' mean? |
2015-09-23 | Computer Security Tips for Beginners |
2015-09-22 | FCC Computer Basics 11: IP Addresses |
2015-09-20 | Computer Basics 14: Content Delivery Networks |
2015-09-20 | The DOM: What's the Document Object Model? |
2015-09-20 | Big O Notation: A Few Examples |
2015-09-20 | The DOM: Style in the Header, Script in the Footer |
2015-09-20 | Big O Notation: What It Is and Why You Should Care |
2015-08-24 | Chrome Dev Tools: Summary Tab |
2015-08-24 | Chrome Dev Tools: Console Tab |
2015-08-24 | Chrome Dev Tools: Audits Tab |
2015-08-24 | Chrome Dev Tools: Resources Tab |
2015-08-24 | Chrome Dev Tools: Memory Tab |
2015-08-24 | Chrome Dev Tools: Timeline Tab |
2015-08-24 | Chrome Dev Tools: Sources Tab |
2015-08-24 | Chrome Dev Tools: Network Tab |
2015-08-24 | Chrome Dev Tools: Elements Tab |