开发者

How to reduce total waiting time of a web page?

I am working on a website. Some of the pages on this website are rendering very slow, say taking arround 16-20 seconds.

I searched on the Internet to optimize web pages.

Everyone says to reduce the size of the web-page or to bunch up all the static contents (that is, JavaScript and CSS) in o开发者_如何学Pythonne file to reduce number of HTTP requests to the server while downloading contents.

But I have some problems regarding this approach:

  1. The source code is massive, and I dont know the impact of merging all JavaScript and CSS file into one file (which functionality would be affected like JavaScript clashes?)
  2. The maximum time is the waiting time for this page (around 14 seconds), and I have already tested the total responce time of the database server and other processes at my local end, that is minimal of around 1 second.

Also, I have tested this page to my staging server, there it's working fine with 2-3 seconds of downloading time only, but at the production server it's taking arround 16 seconds.

  1. If it's a problem of the server, as the page on the staging server is working fine but not at the production server
    1. What would some code optimzation with minimal code changes be?


Everyone says to reduce the size of the web-page or to bunch up all the static contents (that is, JavaScript and CSS) in one file to reduce number of HTTP requests to the server while downloading contents.

This won't do anything in your situation, as the slowness is in the page itself, not the download and parsing of the JavaScript code and CSS.

Also, I have tested this page to my staging server, there it's working fine with 2-3 seconds of downloading time only, but at the production server it's taking arround 16 seconds.

Figure out what's different between them. Clearly, you have a misconfigured production server in some way. If it were something with the HTML, CSS or JS it'd show up on both servers.


Hard to say without more details of the site, but I'd load 'er up in Firefox with the Firebug and YSlow extensions.

Firebug's "Network" tab will show you a timeline of exactly where your browser is spending the most time -- is it downloading? Rendering? etc. -- and YSlow will give you a list of tips on how to speed it up.

Even if it's working fine on your staging server, this could help. Is the staging server taking longer to respond to HTTP requests? Is it transferring data more slowly? Are requests on the staging server not being cached by the browser? It'll be useful info.


Thanks all from responses. The actual problem that was found was quite surprising.

I suspect that some the code logic was there which was creating problem. I use a code profiler tool for analyzing the behavior of my code at run time. After few hour of code profiling i came to know that there was a code block which was searching a string among around 100 thousand files each time and creates a new file each time if the string is not found.

So moral of the story is that Code Profiler tool are very useful in such a condition where you can detect all the resources i.e; Memory, CPU power & space used by your piece of code in graphical & numerical format.

I found the Ants Code Profiler most useful & powerful tool for code profiling. you can see more about this tool using the link: http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

Thanks Rupendra


Do you need all the JavaScript files on the same page? I can see you have a JavaScript file called admin or a file that talks about credit card details and payment? Reduce the number of JavaScript files on the page if you do not need them.

It is always advisable to have your JavaScript files at the bottom of the page to speed up the performance, so give this a shot. Also maybe try using a content delivery network for large files.

Try to "minify" your JavaScript and CSS files. This makes them a LOT smaller in size and helps improve performance.

I really don't understand why you have so many JavaScript files as the example page you have given does not really seem to do much. Have you had a good look at your code to see if you can remove some of the JavaScript code?

However, I think that something is wrong with your production server as the time it takes to load your page is really bad. As a user, I would leave straight away.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜