• Hello guys,

    The AMP plugin has an automatic redirection scheme for mobile versions (https://prnt.sc/xvhu2i). Then, accessing the normal url, it will be redirected to the amp version on the mobile.
    However, I realized that this redirection is very slow
    When analyzing a page on my site in Page Speed Insights (not including ?amp=1 at the end of the URL), it shows that the amp is charging in more than 4 seconds: https://prnt.sc/xvhjaw

    If I analyze the same page but with the parameter ?amp=1 at the end of the URL, the result is much better: https://prnt.sc/xvhelm

    I have activated AMP, with Reader template and Legacy theme.

    Why is redirection so slow? And how to fix it?
    There is no point in having a fast amp version and the redirection (from normal to amp) is slow.

    Thank you!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    We’ll need to see your site in order to identify why the redirection is slow. You can share your site information privately via our form: https://forms.gle/FdNwU37wdBhzTCFV9

    Thread Starter Rodrigo

    (@vejapixel)

    Shared the form.

    Plugin Author Weston Ruter

    (@westonruter)

    Thanks. The redirection is slow for two reasons:

    1. Mobile redirection by default is performed via client-side JS redirection. This is slower than server-side redirection, but it is more compatible across sites. If your cache layer(s) are caching pages with respect to the mobile user agent, you can enable server-side redirection via this PHP plugin code: add_filter( 'amp_mobile_client_side_redirection', '__return_false' );
    2. You have an optimization plugin which is concatenating and minifying all JS on the page and moving it to the footer, including the AMP plugin’s JS for client-side redirection which is added at the wp_head action. For this reason, the entire page is loaded before redirection is done. If you can exempt concatenation for the JS that contains the string amp_mobile_redirect or amp-mobile-version-switcher then the speed should be greatly improved. This was done by default in one such optimization plugin.
    • This reply was modified 3 years, 9 months ago by Weston Ruter.
    • This reply was modified 3 years, 9 months ago by Weston Ruter.
    • This reply was modified 3 years, 9 months ago by Weston Ruter.
    Plugin Author Weston Ruter

    (@westonruter)

    If you can confirm which plugin you’re using that is concatenating and moving the JS redirection code, we can submit an issue to the plugin author to prevent it from being processed by default.

    Thread Starter Rodrigo

    (@vejapixel)

    1. Should I insert this redirect code below, in my theme’s function.php?
    add_filter( 'amp_mobile_client_side_redirection', '__return_false' );

    2. I am using the WP-Rocket cache plugin.

    Thread Starter Rodrigo

    (@vejapixel)

    2. I disabled the “Combine JavaScript files” feature of WP-Rocket (https://prnt.sc/xvu4a1) and the score improved a lot (https://prnt.sc/xvubt2).

    The problem is that when it disable this feature, the desktop score gets worse: https://prnt.sc/xvudua

    And another detail… although the score improves when disabling the “Combine JavaScript files” feature, it is not as good as directly accessing the amp version: https://prnt.sc/xvukj2

    Plugin Author Weston Ruter

    (@westonruter)

    Should I insert this redirect code below, in my theme’s function.php?

    Since you are using the legacy theme, you can put it in the functions.php. But ideally you’d put it in a custom plugin so you can switch to a full Reader theme later.

    The problem is that when it disable this feature, the desktop score gets worse

    I bet there is a way with WP Rocket to keep the feature enabled but to exclude just the script for mobile redirection. We’ll investigate and get back to you next week, ideally with a patch for WP Rocket itself.

    Thread Starter Rodrigo

    (@vejapixel)

    I inserted the code in function.php and the score improved a lot: https://prnt.sc/xx9itn

    If you find a way to delete only the mobile redirect script in Wo-Rocket, I think it’s better than using code in function.php

    Plugin Author Weston Ruter

    (@westonruter)

    If the HTTP redirect works for you, then it will actually be better. It will always be faster.

    Instead of putting the code in your theme’s functions.php, you can put it in a separate plugin like so: https://gist.github.com/westonruter/e5032d805625f0f743237708c43d3783

    Thread Starter Rodrigo

    (@vejapixel)

    I removed the code from function.php, installed the “AMP Mobile Server-Side Redirection” and it is redirecting perfectly.

    I activated the plugin and the redirection is already working automatically. So I don’t need to insert the code in this plugin, right? It seems that this plugin doesn’t even have a configuration screen (at least I didn’t find it).

    Do I need to install and maintain the “GitHub Updater” plugin? If I don’t have this plugin installed, won’t the “AMP Mobile Server-Side Redirection” plugin be updated?

    Plugin Author Weston Ruter

    (@westonruter)

    I activated the plugin and the redirection is already working automatically. So I don’t need to insert the code in this plugin, right? It seems that this plugin doesn’t even have a configuration screen (at least I didn’t find it).

    Correct. There is no UI. This plugin is used instead of adding the code to functions.php.

    Do I need to install and maintain the “GitHub Updater” plugin? If I don’t have this plugin installed, won’t the “AMP Mobile Server-Side Redirection” plugin be updated?

    You don’t need to install that plugin, no. It’s doubtful this plugin will be updated in any way.

    Thread Starter Rodrigo

    (@vejapixel)

    Thank you for your attention.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Redirection to AMP is too slow’ is closed to new replies.