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.
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 domain.com/image.png this to be finally served from static.domain.com/image.png. Domain and subdomain are served from the same server. Varnish already connect to the backend at 127.0.0.1
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?
What is the way to do the same in apache?
varnish really isn't made to do redirects. There are some hacks out there to do it like for example
http://blog.mudy.info/2009/02/how-to-do-http-redirect-on-varnish/
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..