Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How big is "too big" for a javascript file

Tags:

javascript

With all the awesome jQuery plug-ins out there, it's so tempting to just start including them all over the place to enhance the look of our website.

I'm looking for some opinions on whether and when I should be concerned about the sizes of these scripts.

Assume they're being cached on the web server level, so I guess the potential concerns are on bandwidth for the scripts being served from the web server, as well as performance on the client browser that needs to download all these scripts.

like image 852
Edward Shtern Avatar asked Jul 22 '10 15:07

Edward Shtern


People also ask

How big is too big for a JS file?

URLs contain JavaScript files of size over 25 KB. The figure of 25KB is relatively arbitrary – there is no hard and fast rule as to what constitutes an JavaScript file that is 'too large'.

How big should your JavaScript be?

For mobile, aim for a JS budget of < 170KB minified/compressed. Uncompressed this is still ~0.7MB of code.

Does JavaScript size matter?

Large amounts of JavaScript negatively affect site speed in two distinct phases: During page load: big bundles take longer to download. During parse and compile: big bundles take longer to be turned into machine code, which delays JS initialisation.


1 Answers

There are two issues here as you mentioned.

The first is server load. If this is an issue, you can use the Google AJAX Libs APIs, and get your libs directly from Google's CDN.

Second issue is client side loading time. Well, you should decide who your target audience is, and how much you are wiling to let the user wait. As a rule of thumb, most websites today consume ~300KB of bandwidth per page, including scripts, stylesheets and images.

like image 89
Yuval Adam Avatar answered Oct 13 '22 00:10

Yuval Adam