Search code examples
javascriptperformanceasp-classicpageload

JavaScript in classic ASP: Do the <script> tags still belong on the bottom?


Many, many developers wonder where JavaScript references (<script> tags) belong in HTML files. Nearly every authority figure seems to favor references placed at the bottom of the page, excluding jQuery and similar modules.

It's been over a year since I last touched ASP.NET and I have no prior experience with classic ASP. Does the classic ASP compiling/serving process benefit from <script> references that have been moved to the bottom of the page?

I've done some testing and it seems to help, but I can't be sure. If classic ASP does benefit from relocated <script> tags, is the payoff big enough to justify time spent refactoring?


Solution

  • The placement of the <script> tag on the bottom of the pages has two key reasons:

    • The HTML content is loaded before the JavaScript, meaning that the user sees your content earlier on
    • Inside the script, you can assume, that all the HTML is already loaded and is available to the DOM (so no need to wait for it)

    Server-side it doesn't matter where you place it, I think.