I read that browsers sometimes block waiting for multiple images from the same host, and I'm trying to do everything I can to speed up page load times.

One caveat: I need to serve files over HTTPS.

Any opinions about whether this is feasible:

  1. Setup a wildcard cert for *.domain.com.
  2. Whenever I need an image, generate an number based on a hash mod 5 of the filename, and append it to an 'img' subdomain (eg img1.domain.com, img4.domain.com, img3.domain.com, etc.); the hash will make any filename always use the same subdomain, and therefore the browser should be able to cache the images
  3. Configure a dynamic virtualhost record to point all img#. subdomains to /var/www/img

I am looking for feedback about this plan. My concerns are:

  1. Will I get warnings when my page has https:// links to multiple subdomains?
  2. Is the dynamic virtualhost record I'm talking about even possible?
  3. Considering the amount of processing this would require, is it likely to even produce any kind of overall benefit? I'm probably averaging a half-dozen images per page, with only half being changed on each page refresh.

Thanks in advance for you feedback.


Your scheme is possible if you have a wildcard DNS entry pointing to your web server and it is configured to answer on all possible hosts, and you have a wildcard SSL certificate. I do see a few problems though:

  1. By putting each image on a different hostname, you increase the number of DNS lookups required to load the page.
  2. By putting them on different hostnames, you eliminate the ability for the browser to reuse an existing TCP connection for multiple images. Establishing TCP connections is "expensive" and there will now have to be an established connection for EACH image rather than the few that would be established and reused if the images were under the same hostname.

Generally, some good practice for service images include:

  1. Load images from a different hostname than the main domain, but keep them limited to one or two other hostnames (for the reasons stated above).
  2. Ensure that no cookies are used on those hostnames (eliminates the need for the browser to send the cookies along with the request.
  3. Ensure caching is enabled for the content served on those hostnames (not generally applicable for SSL though).
  4. Combine images and use CSS sprites where possible.
  5. Lots of others that have been well documented elsewhere.
  1. No, if all is SSL & valid cert you will not run into trouble.
  2. Yes, at least in apache it is as trivial as setting a single line ServerAlias *.domain.com
  3. Not really in the current state.

A more suitable solution:

Use a lightweight server (e.g. lighttpd with a under a different domain without any heavy modules loaded (lightweight processes), and use only one per server with the appropriate settings. Or even better, use nginx as server as that will:

  1. Require no different domain/port/cert.
  2. nginx serves up the static content, and acts as a reverse proxy server for the 'dynamic' requests to your original, more heavy server, which runs either locally on another port/ip of possibly another server, your choice
  3. set appropriate settings in nginx (like keepalive, workers etc.)
  4. has no problem serving HTTPS
  • These are great tips-- I'll give them a try the next time I have the option of lighttpd/nginx on a project. – iopener Jun 7 '10 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.