Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the recommended JS kb limit for a web app? [closed]

Just wondering if anyone more experienced out there could suggest a recommended limit for total JS resources in a web app. I want to make sure I'm not overloading my bandwidth.

I'm currently around 350 - 400kb spread between two .js files (unminified). This is not including jQuery & jQuery UI from Google CDN.

Thanks!

like image 342
wilsonpage Avatar asked May 09 '11 15:05

wilsonpage


People also ask

How do I reduce the size of a JavaScript file?

Minification can help reduce JavaScript file sizes by removing comments, white spaces, and redundant code, and in some cases, also makes the code more efficient by using shorter variable and function names. The smaller these JavaScript files are, the faster they are downloaded, parsed, and executed by the browser.

What is a min js file?

min. js is a compressed version of jquery. js (whitespaces and comments stripped out, shorter variable names, ...) in order to preserve bandwidth. In terms of functionality they are absolutely the same. It is recommended to use this compressed version in production environment.

What is better to load one complete JavaScript file on all pages or separate files based on different pages?

You should put your JS code in a separate file because this makes it easier to test and develop. The question of how you serve the code is a different matter.

How can I tell if a JavaScript file is loaded?

Pass the URL of JavaScript file in a <script> tag. Set the onload parameter, Trigger alert if script loaded. If not then check for loaded variable, if it is equal to false, then script not loaded.


2 Answers

I suppose there isn't really a recommended "file size" per-say.

More a recommended length of time for your entire page to load, including all css, images, javascript, rendering time etc. Too long and people are going to loose interest, but it really depends on your content i.e. if it's very specific content that people are after, then they will wait for longer, but if your running an e-commerce site and your competition is only a click away, then page-load times are very important.

I suppose the answer is make your files as small as possible and your site load as fast as possible. But this is going to be a classic return on investment question, if your running an e-commerce site, a faster loading site could lead to more sales?

But to try and answer your question, 400KB seems a little heavy to me. As a general rule of thumb, you want to aim for sub 10 second for a sub 2 second load time of the page beginning to be visible - to at least give a response to your user.

Here are Yahoo's Best Practices for Speeding Up Your Web Site

You can also run Y-Slow a firebug add-on, or numerous other speed tests to analyse and give recommendations.

Google's Page Speed site is a more contemporary approach to page speed.

like image 187
Alex KeySmith Avatar answered Oct 28 '22 11:10

Alex KeySmith


I believe it's around 500kb, at which point you start taking serious performance hits.

like image 32
Mike Hofer Avatar answered Oct 28 '22 13:10

Mike Hofer