3

IE has a limit of 31 style sheets (there are ways around that) but is there a limit to how many javascript files i can include? if i go above it, what happens?

i've got a page now with 40+ included js files.

changokun
  • 1,563
  • 3
  • 20
  • 27
  • is there a reason you can't combine and minify the js files? – zzzzBov Nov 11 '10 at 20:35
  • 2
    Q: if i go above it, what happens? A: Nobody knows because everyone who has tried it has perished. – jessegavin Nov 11 '10 at 20:46
  • I'd love to know what needs you have for including 40 separate .js files. – dmackerman Nov 11 '10 at 20:47
  • @zzzzBov: It's irrelevant. Some people just like to *know* these kind of limits. Optimization into single file is (imho) a step you perform when publishing the site to production. During development/debugging we want separate files because it makes live easier. – Stijn de Witt Sep 11 '13 at 07:09
  • @dmackerman: 40 is nothing. If you try to approach a web application in a modular fashion and make components for things like a RichTextArea or a TreeView etc, it's very natural to give each component a separate file. Getting 40 files is than just a matter of placing many components on the same page. – Stijn de Witt Sep 11 '13 at 07:11
  • @StijndeWitt, this question and my comment are almost 3 years old. I'm not sure the answer is quite as relevant now as it was then. Dependency management tools such as requirejs weren't as common (requirejs was only a bit over a year old at the time). With that said, my comment was truly meant as a comment and not an answer. It's a good idea to combine and minify custom js (with libraries coming from a CDN). I also recommend using source maps for development, so that you don't even have to worry about how to go from multiple scripts in development to a single script in production. – zzzzBov Sep 11 '13 at 13:40

2 Answers2

11

I tried it myself and can now say that you can safely import and execute at least 200 JavaScript files in your HTML via script tag with the src-attribue with the following browsers:

  • Win XP IE6,
  • Win XP IE7,
  • Win XP IE8,
  • Windows 7 IE9,
  • Mac OS X Lion Chrome 21,
  • Mac OS X Lion Firefox 15,
  • Mac OS X Lion Opera 12,
  • Mac OS X Lion Safari 6.
Scott
  • 21,211
  • 8
  • 65
  • 72
André Huf
  • 111
  • 1
  • 2
7

Due respect, I think you're asking the wrong question. The correct question is: "I have 40+ JS include files...how do I fix it?"

Check out Google's article on reducing http round-trips, and the benefits of doing so. Combine, minify and deliver your files via gzip whenever possible.

The page not working is one concern, and a valid one...but why not side-step it and greatly improve your users' load time while you're at it by combining and minifying those files now, before you approach any limit? For mobile users round-trips are especially painful, but there's no reason not to offer a more optimal load experience to all your users.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • my thoughts exactly! there are some great tools out there for combining your css files and your javascript files into one file each. combres is a good example – Patricia Nov 11 '10 at 20:39
  • 2
    Listen to this man. It's better to have a HUGE js file than 40+ little ones. It's the http requests that bog down a page. Also *40* - whoa. – Gregg B Nov 11 '10 at 20:44
  • Also, I don't want to know why you needed to find out there's a way around the 31 style sheet limit. Edit - ah here's a reason: http://kenneth.kufluk.com/blog/2010/09/loading-more-than-32-stylesheets-in-ie-for-development/ – Gregg B Nov 11 '10 at 20:46
  • Please listen to the man who knows what he's talking about when it comes to javascript, and don't try and argue with him. There are about 30 good points in his first sentence. – jcolebrand Nov 11 '10 at 20:52
  • well of course it would be ideal to get all these files reduced into a few minimized files, but i'm working on a site that is drupal munged with another cms, so i've got js and css out the wazoo. the client won't pay to have the reduction work done, and everything more or less works at this point. but we're hitting problems with the css stylesheets going over the limit and i'd like to know if anybody has ever hit such a limit with js. thanks for the concerns about mobile users and what not, but minification will have to go to the back burner. – changokun Nov 11 '10 at 21:37
  • @changokun - What prevents you from sticking some of that script in the same file? even if minification isn't an option (and it's *very* easy, it certainly should be) you could reduce the number of reuqests the client has to make. – Nick Craver Nov 11 '10 at 21:43
  • man you guys are tough. the 40+ files is just one page. there's a dozen different pages with similar number of files, but DIFFERENT js files. this is an issue, i know. but if the only price to pay is numerous http trips, that's what the client will pay for. the client will not pay for minification. ergo my original question: has anybody hit a limit on the number of included scripts? – changokun Nov 11 '10 at 21:58
  • @changokun - I don't know of a hard limit no, the limit will be users' patience I'm pretty sure. Honest critique here: it's your job as a professional web developer to tell the client this needs to be done, and honestly it doesn't take 10 minutes to do anyway, there are *lots* of minification resources out there. – Nick Craver Nov 11 '10 at 22:03
  • wow. i'm not sure what to do now; this site is tough to crack. thanks, everyone, for your time. i learned how i will ask my next question: fudge details about the situation so that responses will focus on the question instead – changokun Nov 12 '10 at 16:40
  • @changokun: Only mistake you made is accepting this non-answer. I just want info on the numbers people, so to make informed decisions on preventing how to reach those limits. And yes, 40+ files is a valid option *during development*. Personally I hate developing in/debugging minified files, but that could just be me. – Stijn de Witt Sep 11 '13 at 07:14
  • Has nobody here developed a js application with many components? – Semra Dec 21 '13 at 15:38