Magento performance images and static on CDN

A CDN or Content Delivery Network general works by using a service that provides servers all over the world to quickly deliver media files to the end user cutting down on network latency. This means a CDN benefits your webshop when you have customers from all over the world visiting your shop.

So what you're proposing to do is strictly taken not really a CDN. But that aside there are a couple of things you can do.

  • Set up a subdomain that sends as little extra headers as possible (like cookies) along with the images
  • Configure NginX on your server to service static files. Since NginX is much faster than Apache this will win you some speed
  • Use a service like http://www.jpegmini.com/ to compress your JPEG's further
  • Use a different file server for serving images, a general purpose webserver is configured to serve, in this case, PHP pages. A file server will have a different configuration better suited for quickly serving images.

To serve images from a subdomain you will need to do the following: add the subdomain to your DNS (cdn.shirtsofholland.com), add a server alias to your Apache configuration for the existing package where the shop is running on.

ServerAlias cdn.shirtsofholland.com

Forwarding the subdomain to this package, and then in the Magento Backend go to System > Configuration > General > Web > (un)secure url changing the Base media URL to http://cdn.shirtsofholland.com/

The process for your own server is called Domain Sharding. [Update 11jan2017] Since HTTP/2 Domain Sharding has almost no benefit anymore

In case you do want a real CDN, look at a service like OnePica, Magento extension can be found here or Amazone AWS, Using Ashley Schroder tutorial


You don't need any extra code or plugins to use a CDN that supports origin lookup. These include Akamai, Cloudflare and Amazon's Cloudfront. All that you have to do is point System > Config > Web's JS, Skin and Media URLs at the correct domain:

enter image description here

You can also set up CNAME records in DNS to have the DNS respond on a subdomain to your root domain.


CDN is only 1 building block of your E2E website performance and it serves a very specific purpose which is to provide quasi-unlimited scaling capability and improve the performance/speed at which static objects are served to your site visitors by distributing these static objects to edge servers as close as possible to your visitors across the world using purposed build-optimized delivery servers.

If your audience is spread across the world then it makes a lot of sense to use a commercial CDN solution instead of buying Servers and Bandwidth across the world. Only a handful of companies have the money and expertize to build such Network. Google has done it, Netflix is doing it, but unless you are that big, there is no economical sense in building your own CDN and you are better off using one of the Commercial CDN providers. The leading 3 Tier 1 providers being Akamai, Limelight and EdgeCast.

There are a 100s other CDN providers. It is a bit like the auto business, lots of brands, all have 4 wheels and an engine but there are massive differences between each brands/models.

It is unclear what your audience is or how much traffic you deliver. Without these information it is hard to provide a good answer. however, setting up a commercial CDN is as easy as letting the CDN know which domain serves Static files.

assuming static.shirtofholland.com is used to serve static objects (images, js, css...) then you just need to create that cname, let the CDN know where is the Origin server (so that it can pull the static content and cache it at the edge) and finally update you DNS zone to point that static cname to your CDN provider. Alternatively you can use the CDN URL directly (provided by your CDN). It is not very elegant but it works.

Other important aspect to consider when looking into performance improvement are the following:

  • DNS - is your current DNS provider fast and reliable enough? Using a Managed DNS provider will go a long way and will not cost much money.

  • CDN for static object delivery

  • ADN or DSA for accelerating Dynamic content (non-cacheable). This will improve dramatically the performance of any eCommerce site but it is relatively expensive (unlike CDN which is very affordable).

  • FEO or Front End Optimization which can either be done by code optimization (See Souders' bestselling O'Reilly book, High Performance Web Sites) or using a commercial solution that will apply these FEO rules (and more) on-the-fly to your site. This is usually done on top of Dynamic Acceleration.

Tags:

Performance