Optimal Static Content Subdomain Configuration

Using subdomains for serving static content on your store will improve both performance and cacheability of static assets. Making this change is very straightforward and can be completed in a few minutes.

In this example, we'll assume the domain is www.example.com.

Configure DNS Records

Create three DNS records, one for media, js and skin as necessary (to suit the 3 URL types in the Magento admin).

Record Type Source Destination
CNAME media.example.com www.example.com
CNAME js.example.com www.example.com
CNAME skin.example.com www.example.com

! Be aware that DNS records can take up to 72 hours to propagate. You should wait at least 3 days before proceeding with the next steps.

Create Subdomains/Vhosts

You can use either a subdomain or vhost (read more about domain groups, vhosts and subdomains) to create the links to the static content. There are merits to each (read the previously linked article to find out), so pick the most appropriate one to suit your needs, for most, subdomains are sufficient.

Vhost Method

You should have 3 vhosts, media, js and skin - within each vhost, the http directory should be removed and replaced with a symlink to the respective directory.

cd /microcloud/domains/example/domains/media.example.com/
rm http
ln -s ../example.com/http/media http
cd /microcloud/domains/example/domains/js.example.com/
rm http
ln -s ../example.com/http/js http
cd /microcloud/domains/example/domains/skin.example.com/
rm http
ln -s ../example.com/http/skin http

Subdomain Method

cd /microcloud/domains/example/domains/example.com/
ln -s http/media .
ln -s http/js .
ln -s http/skin .

Change Magento URLs

Log into your Magento admin and go to System > Configuration > General > Web > Unsecure

Configure the URLs for media, js and skin respectively to suit,

Setting Value
Base Skin URL http://skin.example.com/
Base Media URL http://media.example.com/
Base JavaScript URL http://js.example.com/

It is not recommended to change the Secure (HTTPS) URLs as this can cause problems within the Magento admin area itself (if your admin URL matches that of the store view you are changing).

Strip Cookies From Files

Finally, it is recommended to configure a setting on MageStack to strip cookies from the static and semi-static content (as per the optimal Varnish/PageSpeed guide).

In example.com.location.static.conf

if (-f $request_filename) {
  set $magestack_clear_cookies true;

In example.com.location.semi-static.conf

if (-f $request_filename) {
  set $magestack_clear_cookies true;

If using the vhost method, these settings will need to be configured on each vhost as appropriate.