Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Optimizing page load speed practices include to load static assets, like images, css, js, from subdomains, so to increase performance, by using cookieless domains, but most importantly by having parallel downloads from the browser.

I use varnish reverse cache in front of my webserver which serves various websites.

  1. How I can instruct varnish to rewrite url for static files (css,js,png,jpg,jpeg,gif), so they are served by a subdomain? So if someone asks for this to be finally served from Domain and subdomain are served from the same server. Varnish already connect to the backend at

  2. Is it more efficient to do the url rewriting at varnish or at the backend (apache)? I think it would be faster to be done in varnish, since it's at the frontline, right?

  3. What is the way to do the same in apache?

share|improve this question
up vote 1 down vote accepted

varnish really isn't made to do redirects. There are some hacks out there to do it like for example

I personally would not do it that way. The correct way to go about this is in the web app. You change the code to reference different hosts to get the assets from.

So you have

That way you can get around tricking the browser better. And they all hit the same IP and your httpd config just has those hosts in a alias for the main domain.

You will actually slow things down doing the redirect due to the client making another request once it gets the redirect. What you want to do is really a bandaide fix to the solution that will show little speed improvements..

share|improve this answer
Thanks for your answer. How I can express in code the following logic: sub vcl_recv { if (req.url ~ "\.(png|gif|jpg)$") AND THEN REDIRECT to ? – john Jun 1 '11 at 4:13
like I said.. its not a good idea to do that.. Your browser will make 5 parallel connections.. wait for the redirects.. then another 5.. You pretty much are at the same speeds as not doing it at all.. – Mike Jun 1 '11 at 12:15
you are right thanks – john Jun 1 '11 at 14:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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