1

I have too much of javascript in the beta site of mine which will be the real one, So what I am thinking is to make the javascript external BUT this raises some really important questions.

  1. What is the standard size for an external javascript (e-g should be never more than 50KB per file).
  2. How many javascript files should be make if the above question is answered like that the size doesn't matter, then does it mean I should put all scripts (including Jquery library) in one external file?
  3. If a javascript is already minified and it is added with other files that are not minified will it effect the one that is already minified?
  4. What is the best minifier for Javascript and CSS (best means that maintains the standards).
  5. If I place the external script just after <body> is it good enough?(as if I go more lower some scripts might stop working).

Here is the link to beta site just incase if you want to check http://bloghutsbeta.blogspot.com/

2
  • #4 should be an extra question, because it is very broad (if not even too vague). Commented May 3, 2012 at 9:32
  • @bergi you are right about it, but I thought instead of making 5 questions out of it, I made one as they all are linked to external javascript method anyway but I do agree it is a broad area to discuss. Commented May 3, 2012 at 9:34

2 Answers 2

3
  1. There is no "standard size" per say, but it's always good to keep file sizes at a minimum. Gmail, Google Maps etc. for instance, load many MBs of Javascript.
  2. The fewer the JS files, the better in general, as the number of connections to the web server serving them are reduced, thus resulting in reduced load.
  3. No, mixing minified and un-minified files should not be a problem.
  4. JSMin and UglifyJS are popular compressors.
  5. You should attach your executions to appropriate events such as document.ready so that scripts don't stop working because the page hasn't loaded fully.
Sign up to request clarification or add additional context in comments.

Comments

1

What is the standard size for an external javascript (e-g should be never more than 50KB per file).

There isn't one.

How many javascript files should be make if the above question is answered like that the size doesn't matter, then does it mean I should put all scripts (including Jquery library) in one external file?

In general, the fewer the better. There are exceptions. (e.g. it might be more efficient to load jQuery from a public CDN that visitors might already have a cached copy from).

If a javascript is already minified and it is added with other files that are not minified will it effect the one that is already minified?

Not if done properly.

What is the best minifier for Javascript and CSS (best means that maintains the standards).

Subjective.

If I place the external script just after is it good enough?(as if I go more lower some scripts might stop working).

It depends on the script. Some schools of thought say that you should front load all the markup (if scripts "stop working" then fix the scripts), other say they should register event handlers using event delegation as soon as possible so users don't interact with controls that aren't wired up with JS before the page has finished loading.

2 Comments

Well if selection of minifier is subject still I would like to hear about one from you as you people are at another level then me so it would be much better than the one I select for Javascript and CSS
Shopping recommendations are off-topic for Stackoverflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.