I’m trying to set up a subdomain/cdn structure to help to parallelize the loading of page resources. The main domain will be accessed under https://www.example.com always.

The assets files (js, css, etc) will be in a github repo on https://www.example.com, but in order to parallelize these assets with other content on this domain, I’d need to utilize a subdomain such as assets.example.com.

Accessing the assets files would look like this: https://assets.example.com/js/file.js

https://assets.example.com isn’t an actual web directory so the files would have to be referenced from the other location. Essentially assets is an alias, but doesn’t fully redirect.

What I’ve tried already is setting assets.example.com as a CNAME of domain.com, but it doesn’t seem to work. My next thought was to create an A record, and use htaccess to disable access to any files other than files in specific directories.

In the end I want to be able to access https://assets.example.com/js/file.js and have it resolve to https://www.example.com/js/file.js

Will this work & are there better solutions?

  • You shouldn't bother with this kind of approach anymore. Use HTTP/2 on your site and you will get the same multiplexing benefits without establishing extra TCP connections. This kind of resource splitting to different domains was useful years ago, when SPDY nor HTTP/2 existed. – Tero Kilkanen Aug 17 '17 at 22:47
  • @TeroKilkanen It appears to only have 80% supported across current browser versions. See caniuse.com/#search=http2. Does http2 have a fallback? – stwhite Aug 18 '17 at 0:34
  • If you use multiple domains for clients that have HTTP/2, then you are making their performance less than they could achieve. So, if you want to implement multiple domains, you should check if the browser has not connected with HTTP/2, and then serve resources from multiple domains. And 80% is quite a high number, and it keeps increasing. Of course if you think it pays the effort to implement this, then you can implement it. You need to make sure your web server has the appropriate virtual host configuration so that all your domains are served properly. – Tero Kilkanen Aug 18 '17 at 7:16
  • Another issue with domain sharding when using TLS is that you will get an extra TLS handshake for every connection you make to a separate domain. This handshake adds to the total transfer time of the resources, and therefore you might not get any benefit from the sharding. – Tero Kilkanen Aug 19 '17 at 10:21

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.