Palani
Palani

Reputation: 1921

Javascript execution time is very slow - Chrome

I created webpage which has JavaScript in single file but the size is very high. When I run the page, the loading time of JavaScript is very high in Chrome. FYI: The script file created from excel tool which has lot of hidden fields and scripts but everything needed to make application worked.

Have you anyone gone through same thing and what is the solution we can make for this? Thanks in Advance.

Upvotes: 0

Views: 5078

Answers (6)

Stefan
Stefan

Reputation: 5662

You should determine what´s taking time. Both FF and Chrome has a feature that shows the network traffic. Have a look at yslow as well, they have a great addon to Firebug.

Upvotes: 1

keymone
keymone

Reputation: 8104

Chome's auditing tools can tell you a lot about why is this happening, you should probably include more information about:

  1. how long did it take to connect to server?
  2. how long did it take to transfer content?
  3. how much other stuff are you loading on that page simultaneously?

anyway even without all that, here's a checklist to improve performance for you:

  1. make sure your javascript is treated and served as static content, e.g. via nginx/apache/whatever directly or cdn, not hitting your application framework
  2. investigate if you can make use of CDN for serving javascript, sometimes even pointing different domain names to your server makes a positive impact, e.g. instead of http://example.com/blah.js -> http://cdn2.example.com/blah.js
  3. make sure your js is served with proper expiration headers, don't re-download it every time client refreshes a page
  4. turn on gzipping of js content
  5. minify your js using different tools available
  6. put your script tags just before </body>
  7. investigate and cleanup/optimize your onload and document.ready hooks

Upvotes: 1

Yvo
Yvo

Reputation: 19273

There are a couple of things you could do:
- minify your scripts (e.g. with Google closure compiler)
- combine your scripts (reduces the number of requests)
- turn on gzip compression
- load your scripts at the end of your body tag
- use a CDN, prevents loading your scripts all from the same location (most browsers will only load 2 files simultaneously from the same location)

Have a look at the YSlow plugin and Google PageSpeed, both very useful in improving performance.

Upvotes: 5

Mutation Person
Mutation Person

Reputation: 30530

There is no 'generic' issue of slow loading in chrome. It will all be down to individual scripts.

You'll need to determine 1) Which script is causing the slow load by process of elimination and then 2) Which part of the script is loading slowly, then you can take remedial action.

This could include minification or code refactoring.

Tools like fiddler2 will help you track this time, as you'll be able to view the indivdual page items load time.

Upvotes: 1

fengd
fengd

Reputation: 7579

Combine your scripts into as few files as possible, and minify them. Also load the scripts at the end of your page.

Upvotes: 1

Mike Thomsen
Mike Thomsen

Reputation: 37524

Run it through a script which combines and minifies it. There are plugins for most build systems now that do that. That's how we compress about 1.5mb of JavaScript into about 500kb during our build process.

Upvotes: 2

Related Questions