Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6077355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:42:41+00:00 2026-05-23T10:42:41+00:00

Is there any difference (performance, best practices, etc) between using a single script tag

  • 0

Is there any difference (performance, best practices, etc) between using a single script tag with embedded code in it, or using multiple script tags with the same code spread all over the HTML?

For example:

<script>
    foo();
</script>
...
<script>
    bar();
</script>

versus:

<script>
    foo();
    bar();
</script>

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:42:42+00:00Added an answer on May 23, 2026 at 10:42 am

    With inline script like what you quoted, there’s unlikely to be much difference; however, every time the browser’s HTML parser encounters a script tag, it:

    • Comes to a screeching halt
    • Builds up a string of the the text in the tag up until the first time it sees the string "</script>"
    • Hands that text off to the JavaScript interpreter, listening for output the interpreter sends it when you do a document.write
    • Waits for the interpreter to finish
    • Inserts the accumulated output received into the parsing stream
    • Continues its parsing

    So increasing the number of times this sequence has to occur can, in theory, increase your page load time. It also affects the degree to which the parser can “look ahead” in the token stream, which may make it less efficient.

    All of which sounds really dramatic, but you’d have to profile a real page in the various browsers you care about to determine whether it had a real-world impact.

    So in summary, combine them as much as you reasonably can. If you can’t reasonably combine a couple, don’t worry about it too much until/unless you see a real-world problem.

    The above is for inline script. Naturally, if you have several script tags referring to a bunch of external JavaScript files, you’ll also have the issue that each of those files has to be downloaded, and initiating an HTTP request is an expensive thing (comparatively) and so it’s best, in a big way, to combine those into a single file.

    Some other things to consider:

    • Having lots of script tags scattered throughout your HTML may make it difficult to do maintenance on the script
    • Separating your HTML and script into separate files helps you limit the degree to which they’re coupled, again aiding maintenance
    • Putting script in a separate file makes it possible to run that file through minifiers/compressors/packers, minimizing the size of your code and removing comments, thus leaving you free to comment in your source code knowing those comments will be private
    • Putting your scripts into external files gives you the opportunity to keep things separated by functionality, and then combine them into a single file for the page (compressed/minified/packed) for efficient delivery to the browser

    More:

    • YUI’s “Best Practices for Speeding Up your Web Site”
    • Google’s “Web Performance Best Practices”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any difference (performance, best-practice, etc...) between putting a condition in the JOIN
Is there any difference in performance ( speed wise ) between a synchronous request
Is there any difference in performance - or otherwise - between: ptr->a(); and (*ptr).a();
Is there any performance difference between tuples and lists when it comes to instantiation
Is there any performance difference between the for loops on a primitive array? Assume:
Is there any performance difference between: p { margin:0px; padding:0px; } and omitting the
Are there any performance difference between decimal(10,0) unsigned type and int(10) unsigned type?
Is there any difference in (asymptotic) performance between var a = Orders.OrderBy(order => order.Date).First()
What is the main difference between StringBuffer and StringBuilder ? Is there any performance
Is there any performance differences between string.Format and String.Format ? As far as i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.