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

  • SEARCH
  • Home
  • 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 7789739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:23:25+00:00 2026-06-01T21:23:25+00:00

Let’s say I’m building a static 10-page website for a client, and there’s only

  • 0

Let’s say I’m building a static 10-page website for a client, and there’s only a few lines of JavaScript for the whole site (less than 1KB). In this situation I’d guess that it’s best (for performance) to put the <1KB of JavaScript code inline between script tags on every page, rather than in an external .js file. The extra bandwidth consumption (when moving between pages) is probably worth it for removing a whole HTTP request.

At the other end of the spectrum, if I had 200KB of JavaScript on the same website, then I’d definitely put this in a separate file to reduce bandwidth when moving between pages on the site.

But I’ve no idea where the ‘cut-off point’ should be. If I have 5KB of JS, should I just put this inline in my HTML? What about 10KB? 20KB?

Obviously the ‘cut-off point’ is going to depend on the situation, e.g. it might be different for mobile sites. But if anyone has any general pointers that would help guide this decision, then I’d like to hear them.

(NB: I’m interested only in performance here, not maintainability etc. I can keep my code in separate files but use some kind of build process or serverside middleware to automatically inline it, so maintainability will not be an issue.)

(Bonus points: please let me know if all the considerations are exactly the same with inline vs. external CSS.)

  • 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-06-01T21:23:26+00:00Added an answer on June 1, 2026 at 9:23 pm

    I’m strictly talking about performance here, more as a thought experiment (and please excuse the lack of experimental rigor).

    If you’re inlining the javascript, yes you do save time in the fact that everything is done in one http request. However, you should factor in the time it takes for a server to dynamically generate the webpage that you need (SSL also adds time to this).

    Best case

    If you can create a build that generates minified javascript and injects it into an html page, combined with gzip compression, you should result in a much lower bandwidth. The more text you stick in the compression, the bigger your payoff compared to individually gzipping per request. Ultimately, this means if you can have it load a single html page statically with all the javascript/css inline, this means it will definitely be faster.

    Normal case (with dynamic html and shared js libraries)

    A small sample of some stackoverflow posts and how they affect my own bandwidth:

    304ms 9.67KB
    204ms 11.28KB
    344ms 17.93KB
    290ms 17.19KB
    210ms 16.79KB
    591ms 37.20KB
    229ms 30.55KB
    

    Judging from this, it seems like the overhead incurred (disregarding filesize) is around 150ms for each http connection – perhaps in the worst case. Now, the question is, how big does the text (javascript in your case) have to be for your bandwidth to incur 150ms. According to this article (http://www.telecompetitor.com/akamai-average-u-s-broadband-connection-speed-is-now-5-3-mbps/), for broadband users, we are working with an average of 5.3 mbps (which is .6625 MB/s or 678.4 KB/s or .6784 KB/ms). This means that for the average broadband user, you will need roughly 100KB download of gzipped+minified javascript for it to equal.

    Please adjust the parameters yourself to see what this may mean for your audience. This number, whatever you calculate it to be, is the point at which you may be better off serving it inline (through server-generated response) versus fetching it/caching it externally.

    All in all, I don’t think that for performance reasons, this is a bottleneck at all. The size of compressed + minified javascript is usually negligible and it has to be on orders of unmaintainable magnitude that it would matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm building a data access layer for an application. Typically I have
Let's aggregate a list of free quality web site design templates. There are a
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's assume that we are building a high traffic site that will be used
Let's say there is a graph and some set of functions like: create-node ::
Let's say I wanted to remove vowels from HTML: <a href=foo>Hello there!</a>Hi! becomes <a
Let's say I have an abstract parent class called shape, and that there are
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say a user is visiting my app website for the first time, so
Let's say you create a wizard in an HTML form. One button goes back,

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.