Question

While reading up on some Magento I was again attracked to the following: How can I set-up a Magento CDN on local server by subdomain? [also see attached images]

I am envisioning to set-up cdn.mymagentoserver.com, have it point to the same public_html folder as www.mymagentoserver.com and change the media directories as shown below.

Question:

  1. how does one set-up a subdomain like described?

Additional to think about

  • would it also work for all domains of a multistore?
  • how about when I add https in the future? Wouldn't the images be coming from an unsafe domain if I had a SAN certificate? or would I just add the subdomain too
  • Is this all worth it?

enter image description here

Was it helpful?

Solution

It's possible, but by definition not a CDN (content delivery network)

There are still advantages though: if you set up the cookie domain in Magento to www.example.com, cookies will not be sent with requests to static.example.com, making the requests a bit more lightweight and faster (also: more cachable). The cookie domain can be set up in the same config section as the base urls. If your base URL is like example.com without "www", use example.com and pay attention that it's not prepended by a dot (because .example.com would include all subdomains)

Screenshot

Another argument is that browsers limit the number of parallel requests per domain, so having a second domain can speed up total page load as well. But this is not so relevant today anymore, so take it with a grain of salt and especially don't start to distribute the requests over more than two or three domains.

The success of domain sharding can be mitigated if it’s done incorrectly. It’s important to keep these guidelines in mind.

  1. It’s best to shard across only two domains. You can test larger values, but previous tests show two to be the optimal choice.
  2. Make sure that the sharding logic is consistent for each resource. You don’t want a single resource, say main.js, to flip-flop between domain1 and domain2.
  3. You don’t need to setup different servers for each domain – just create CNAMEs. The browser doesn’t care about the final IP address – it only cares that the hostnames are different.

Source: http://www.stevesouders.com/blog/2013/09/05/domain-sharding-revisited/

As for your question how to set it up: ask your hoster. They can either do it for you or tell you how to do it. It's not exactly the same on every system.

OTHER TIPS

This is extremely simple to achieve and there is absolutely value in making this change despite not using a formal CDN.

CDN's don't always improve performance for your domestic market (in some cases it will make it slower). You'll lose nothing setting up a few sub domains, and potentially gain a little.

The real advantage to using sub domains for static content is to ensure the content is served cookie free. If content doesn't have a cookie, its more cacheable (whether by a reverse proxy like Varnish or the browser itself). There's so the fact that modern browsers cannot pipeline more than a handful of requests to a single domain at once, introduce multiple domains (or sub domains) and you can suddenly increase that parallelism by a factor of however many sub domains you use.

When you consider that almost 90% of your traffic is HTTP, that means that 90% of your customers will benefit. For HTTPS, keep it simple and to a single domain - when a customer is browsing a HTTPS page, its the checkout anyway, so there's little gains to be made.

Setting it up is as simple as adding the sub domains (js/skin/media), and symlinking them to the respective folder as necessary.

Takes about 3 minutes to configure, its free, requires nothing complex, and will give instant/immediate improvements.

Take a look at CloudFlare. If you are comfortable making some DNS changes then this should be pretty easy to setup. Basically, your webserver acts as the origin server. CloudFlare then hits your server once to cache each file (on-demand). Any changes to files in Magento will require you to manually purge the CDN cache or wait for the cache expire.

To make things easier, I would recommend you keep the folder structure the same. If you want to change the folder, this shouldn't be too hard with a rewrite rule. Additional stores would just require additional CNAMES to match your additional store domains.

SSL is easy with CloudFlare if you want to use their cert. You can also use your own if you have a wild card or a separate cert for the subdomain. https://www.cloudflare.com/ssl

If you want more options, also check out AWS CloudFront. It is a little hard to setup but it is more flexible. http://aws.amazon.com/cloudfront/

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top