Fastest Way to redirect a user to another page if website was opened from mobile

Hello,

Would like to ask which you consider the fastest way to redirect the user to a specific page if website was opened from a mobile device:

I tested the wixLocation API however, it will redirect the user after a noticeable timeframe.

I also tested a better solution, I placed a custom code script in the header and it works faster.

Do you know any other solution?

<script>
  document.addEventListener('DOMContentLoaded', function() {
    if (/Mobi|Android/i.test(navigator.userAgent)) {
      window.location.href = "https://www.website.com/home-mobile";
    }
  });
</script>

Are you able to share more about what you’re hoping to achieve?

Are you looking to direct to a completely different site?