You should not use Apex domain with ALIAS record
Tags: netlify, webdev, webperf, dns
Published: 2020-03-07 08:59:14

Apex domain, it's also called naked domain, is a kind of domains without sub-domain.
I've been using it for my app, [Inkdrop](https://www.inkdrop.app/) whose domain of the website was inkdrop.app but now it's moved to www.inkdrop.app.
I deploy it on [Netlify](https://www.netlify.com/) which are often mentioned as a fast web hosting service.
I saw many websites performing very fast with Netlify, but my website didn't have such speed. Especially, the [TTFB (Time-to-first-byte)](https://en.wikipedia.org/wiki/Time_to_first_byte) was extremely long, usually longer than 200ms and it takes 800ms to transfer only 120KB. Why?

![Screen Shot 2020-02-29 at 21.19.10.png](https://cdn-images-1.medium.com/max/1600/1*9XjKmulaC3_m6tdpNBALqQ.png)

## ALIAS record disables geo-targeting

If you have your own domain, you have to configure a `CNAME` record to point it to the Netlify's domain.
But Apex domain is not supported setting a `CNAME` record by design.

To host a website with an Apex domain on Netlify, one option is to use `ALIAS` record instead:

https://docs.netlify.com/domains-https/custom-domains/

I'm using [NS1](https://ns1.com/), a DNS hosting service which supports configuring `ALIAS` record.
I found [their documentation](https://help.ns1.com/hc/en-us/articles/360017511293-What-is-the-difference-between-CNAME-and-ALIAS-records-) mentioning about `ALIAS`:

> #### Disadvantages of an ALIAS record
> 
> * **Geo-targeting information is lost.**  
>   Since it is the_authoritative_server for[example.com](http://example.com/)(issuing the queries for[lb.example.net](http://lb.example.net/)), then any intelligent routing functionality on the[lb.example.net](http://lb.example.net/)record will act upon the location of the authoritative server instead of your location. The EDNS0 edns-client-subnet option_does not_apply here. This means that you may be potentially mis-routed. For example, if you are in New York and the authoritative server for[example.com](http://example.com/)is in California, then[lb.example.net](http://lb.example.net/)will think you are in California, and will return an answer that is distinctly sub-optimal for you in New York.

Ouch.

So, with `ALIAS` record, Netlify is not able to know where visitors are from or to optimize the traffic route.
[I asked Netlify](https://community.netlify.com/t/very-slow-ttfb-on-two-netlify-sites/9844) that it is due to `ALIAS` record:

![](https://cdn-images-1.medium.com/max/1600/1*RqMjfSgimnN8hO3li0GB_A.png)
Unfortunately, that seems to be true.
I decided to move my website to `www` sub-domain.
Apex domains look beautiful (for developers), but it seems like not a big deal for visitors.
I found that recent browsers strip `www` from their address bar like Chrome:

![Chrome](https://cdn-images-1.medium.com/max/1600/1*ghdimEBcvZ28lolAHxVugA.png)
and Safari on iOS:

![Safari](https://cdn-images-1.medium.com/max/1600/1*-XJvU1PMzMbnmmdXUtaPbA.jpeg)
As [stated](https://bugs.chromium.org/p/chromium/issues/detail?id=881410#c18) by a Chromium developer, the `www` and `m` (for mobile) subdomains are being classified by Google as "trivial" subdomains because they feel most people do not need to be concerned with the information they represent.

I guess I am also not caring about `www` subdomain when visiting websites because I didn't notice that Netlify's website is actually `https://www.netlify.com/`.
So, it would be fine.

## TTFB improved from 275ms to 73ms

As you can see, it has been significantly improved after moved it to `www.inkdrop.app`:

![](https://cdn-images-1.medium.com/max/1600/1*mFUD451udp8x4ncJnfCKfQ.png)
The download speed has been also improved. Cool.

## Still need Apex domain?

As fool said above, you have two options at present:

1. Netlify DNS hosting, since they can (and do) use linked A records which do allow geolocation
2. Cloudflare’s CNAME flattening, since that does not seem to interfere with Netlify's geolocation

Why I didn't choose it is because I've already adopted NS1 and just switching to `www` was the quickest way to solve my issue.

Hope that helps improve your website!

* * *

* Twitter: [https://twitter.com/inkdrop_app](https://twitter.com/inkdrop_app)
* Instagram: [https://www.instagram.com/craftzdog/](https://www.instagram.com/craftzdog/)

[![](https://cdn-images-1.medium.com/max/2372/1*-J5tp1_lulY9QknoLEv6zA.png)](http://eepurl.com/dNgJo6)

[![YouTube channel - Dev as Life](https://dev-to-uploads.s3.amazonaws.com/i/yoj5abu9fdhnhvzg3z1w.png)](https://www.youtube.com/c/devaslife)