How to speedup webpage loading? main issue is queue time
Ive been working on my personal page which is based on drupal. Ive noticed that it takes forever to load 6-10 seconds often.
After looking into some performance tests, specifically from site-perf.com, I noticed that the 开发者_开发技巧load time is 80% queue time.
It seems lightbox2 and my theme contribute about 2/3 of the queue time.
Any suggestions on speeding this up?
When you add javascripts to your pages (such as lightboxes or any other addons), make sure to defer their parsing by adding them to the bottom of your page instead of adding them to the head.
The browser will parse anything in the head before rendering the webpage, so take anything that doesn't need to be there, such as a lightbox include or other custom scripts you have included or written in the head and include them just before the closing body tag.
I also noticed that 8 js files (and a ton of CSS files) are included, you can reduce rendering time by placing the code of all of these javascripts into a single js file (and all the CSS into a single file) and include just that one.
A note, make sure to keep CSS in the head of the page as it is necessary to correctly render the webpage.
Remember to cache and gzip your files in the .htaccess file in your root directory. If there isn't one, make one, and then add this snippet:
#GZIP ----------------------------
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifmodule mod_php4.c>
php_value zlib.output_compression 16386
</ifmodule>
#CACHE ----------------------------
<ifModule mod_headers.c>
# MONTH
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|pdf|txt|mp4|m4v|ogv|webm|ogg)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# DAY
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>
# NEVER CACHE
<FilesMatch "\.(pl|php|cgi|spl)$">
Header set Cache-Control "max-age=0"
</FilesMatch>
</ifModule>
Once you're caching and gzipping, try to combine any files that aren't parallel loading. If you find a file that's waiting for another to load before it starts to download, then if possible, combine the two into a single file.
Quoting from mentioned http://site-perf.com/ website:
Request is waiting in queue
Usually, browsers do not begin to process http-request as soon as it is enqueued, preventing web-servers from overloading. There are per host limit of simultaneous connections, and total limit of all connections. These limits vary from browser to browser, and today are common values of 8-10 parallel requests per host and 32-128 total.
Hint: If you see that many requests spend much of its time in browser queue, you could consider increase number of hosts that will serve these requests. You even can create domain aliases which point to same IP and are served from the same directory, because browsers looks only on domain names, not its IPs when applying connect limits. But remember, that each additional domain will add corresponding resolving and connecting delays, so 3-6 such aliases are quite enough.
You could try something like Parallel module - http://drupal.org/project/parallel - to see whether that would speed things up for you. Or, if you want even more, and feeling a bit adventurous - CDN - http://drupal.org/project/cdn
I assume you have all your CSS/JS already aggregated? Caching enabled?
精彩评论