Yslow recommends that you should put scripts at the bottom of the page.
Where exactly should I put them, after the body end tag?
My whole site runs in jquery, so all the javascript files are needed at the beginning. If I move them to the end, it might stop my site from working. That being the case, where instead should i put these scripts for best performance?
When you place your JavaScript at the bottom of your HTML body, it gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and speed up website response time.
Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
When you place a script in the head section, you will ensure that the script is loaded before anyone uses it. Scripts in the body section: Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.
If you include external js files at the bottom of your page, you give the priority of your HTTP requests to the visual display that will be presented to the client instead of to the logic of interaction or dynamics.
You should put them right before the closing body tag. Make sure your scripts are being initiated properly using
$(document).ready()
And you should have no issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With