Amplify: you shouldn’t allow redirect from apex to www

Yan Cui

I help clients go faster for less using serverless technologies.

Update 04/08/2022: turns out there are some valid reasons (analytics and potentially SEO) for redirecting from the apex domain to www. Please see comments from Michael Hart, Mike Lamb and Tyler Love to my tweet here for more details.

 

I have used Amplify to host all my single-page applications, including the newly revamped sites for the AppSync Masterclass and Production-Ready Serverless. In general, I have loved how easy it is to set up, even for a frontend development newbie like me!

You just point it to your repo, select a branch and off you go.

If you own a domain, you can also easily attach the domain to an Amplify project. In the configuration screen, you are presented with the option to set up a redirect from the apex domain name to the www domain name, as you can see below.

If enabled, Amplify configures a 302 Temporary Redirect response from the apex domain to the www. domain.

This option is enabled by default when you add the domain via the AWS console.

I never understood why it’s the default, but didn’t think hard enough about the downsides of it so I’ve always gone along with it.

Until now…

As I rebuilt the landing pages for both AppSync Masterclass and Production-Ready Serverless I have paid special attention to performance, especially on mobile. In fact, I have shared a lot of my learnings in my last post, so give that a read if that piques your interest.

One thing that became painfully obvious as I ran performance test after performance test is that this redirect really hurts the mobile experience. It adds 500ms-800ms to the “time to first byte” on mobile thanks to the extra DNS lookup (green), connection (orange) and SSL handshake (purple) as you can see below.

After all my other optimizations, this 302 redirect alone accounts for over 25% of the “time to interactive“. That is, the amount of time it takes for the site to be fully interactive and usable by the user.

If performance is important to you (and I argue that it always should be) then disabling this redirect behaviour is probably the easiest optimization you can do. And so far I have not seen any downsides yet, nor have I been informed of any potential problems that I hadn’t foreseen.

You might reasonably argue that the DNS overhead is much smaller on desktop. But with more and more users coming from mobile, it’s imperative for us to take mobile performance seriously and make it a first-class citizen. In fact, if you’re a solo entrepreneur like me and you are using social media to promote your info products then this is even more important for you. Because most of the people that are consuming your social media content do so on a mobile device.

For example, every time I promote my info products on social media I would see a big swing in the visitor numbers towards mobile.

Given trends like this, it’s silly not to do everything in your power to make sure these visitors get a good experience.


Whenever you’re ready, here are 3 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game.
  2. Consulting: If you want to improve feature velocity, reduce costs, and make your systems more scalable, secure, and resilient, then let’s work together and make it happen.
  3. Join my FREE Community on Skool, where you can ask for help, share your success stories and hang out with me and other like-minded people without all the negativity from social media.