Magento Performance – Using CDN for Images and Static Files

performance

We are investigating further Magento speed improvements. What we see now is that with the following setup the page flies. Only the images come later. The main files are delivered in a couple of milliseconds, but the loading time is still 2 seconds because of the images.

  • mage caching
  • merge css/js
  • minify apc + memcache
  • htaccess tweaks
  • session/cache on tmpfs

My question: what are the steps to setup a CDN (on my own server)?
(and does it actually help)

I understand it is something like this (but this is not at all working):

  1. create cdn subdomain
  2. change document root (and/or why set a cname?)
  3. change config

Best Answer

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

Related Topic