What is bad about having a script tag inside div inside body?
I'm dynamically updating a div to reload a javascript code inside a div. Are there any issues to worry about ?
As @Bergi insisted on seeing the code. Here it is(see below). This div
(along with other div
(s) containing presentation HTML elements) are updated via AJAX. This script
inside div
contains maps to do processing of newly loaded HTML elements on page with raw data.
<div> <script type="text/javascript"> var namesMap = <dynamic string from server here>; var addressesMap = <dynamic string from server here>; </script> </div>
JavaScript in <head> or <body> You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
The script tag should always be used before the body close or at the bottom in HTML file. The Page will load with HTML and CSS and later JavaScript will load.
In my experience, script tags are bad if they cause your site to load slowly. Site speed actually does have an impact on your appearance in SERPs, but script tags in and of themselves aren't necessarily bad for SEO.
The best practice is to put JavaScript <script> tags just before the closing </body> tag rather than in the <head> section of your HTML. The reason for this is that HTML loads from top to bottom. The head loads first, then the body, and then everything inside the body.
It is perfectly ok to place the <script>
tag anywhere in the body of the document.
From here,
The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document.
However, whenever a <script>
tag occurs, it pauses the parsing of the code till the script gets loaded, and executed.
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