views:

118

answers:

4

I am currently in the process of improving my grails website performance and following many best practices I found on the internet, I currently need to make a decision between two solutions before refactoring my code

  • Solution 1 : Export all of my static resources (js, css, images) to a separate domain and server (as already done by SO team - see here).

  • Solution 2 : Just keep my resources into my WAR file and configure apache to act as a reverse/caching proxy so that incoming requests to /images, /css, /js etc are all cached by apache.

What do you recommend and what are the pros and cons?

PS: Concerning solution 1, is there any web hosting providers specialized for static content out there?

Thank you.

+1  A: 

You should only do this if you've profiled and determined that latency caused by the browser queuing up the downloads is a major factor in the performance of your site. If the static resources load in a few miliseconds, but the HTML itself takes 3 seconds to download after the server has to hit the database ... then improving those few ms won't do much.

Joel Martinez
+1: Agreed, sounds like premature optimization.
OMG Ponies
I have already identified that downloading my static resources is a bottleneck. That said, what solution do you advice and why ?
fabien7474
@OMG Ponies : This is really not premature optimization ! First, if I do optimization, this is because I have already identified a need for that. Second, take a look at this article (http://www.yuiblog.com/blog/2006/11/28/performance-research-part-1/) and you will learn that the first step for optimizing is to reduce HTTP requests because 40% of your users are first-users and do not use browser cache. Therefore, you should deal first with your static content that can be optimized and bundled
fabien7474
+1  A: 

Solution one is the better solution. If you haven't already, you should consult the YSlow performance guide, as it will talk about this in greater depth.

Generally a browser will load page resources in a parallel fashion. However, the browser will limit the number of requests to a specific domain, so if all your resources are on that domain, some of them will block until a previous parallel request finishes. Splitting your resources to different domains facilitates this particular bottleneck, as you can have multiple requests going to images.yourdomain.com and flash.yourdomain.com at the same time. Building your application to utilize this style of resource separation from the start can be a benefit later, even if you serve them all from a single server initially.

You can implement all of Solution 2 as part of Solution 1, ie. have caching on your multiple domains. Generally it's cheaper to start with #2, as you can continue to serve from your existing servers, but have them configured for caching.

Once the big traffic starts you hit and you really want to optimize performance, splitting out your domains can make a difference.

zombat
A: 

It depends on how many resources your page/pages require. Remember browsers can only make a limited number of connections from a single server at a time. For IE 8 this is 2 at a time. If you have 40 resources you can only retrieve them 2 at a time. Spreading your resources out amoung multiple subdomains can greatly increase the speed of page loads on your site.

You can setup a number of CNAME records in your DNS all pointing back to the same physical server and greatly increase the speed of resource loading.

Also check out Google PageSpeed for additional ideas on speeding up your page loads.

Jeffrey Hines
Hi Jeffrey. I am not sure that increasing the number of CNAME will always speed up your page speed. Actually, from what I have read, a minimum of 2 domain names is required up to 4 domaine names. After you get significant performance dropdowns. See this article for more details : http://www.yuiblog.com/blog/2007/04/11/performance-research-part-4/
fabien7474
+1  A: 

If you're not already using it, I'd take a look at the ui-performance grails plugin. It implements many best practices around caching, minifing, and compressing things right out of the box.

As other posters have noted, I'd make sure that you know where your bottleneck is before doing anything too drastic.

Ted Naleid