Support » Plugin: AMP » Redirection to AMP too slow

  • Resolved iamlaurie

    (@abanista)


    I’m using this plugin in transitional mode, but I’m getting im getting a slow AMP redirect. I thought the plugin would just check if page is mobile and if true returns an AMP page but what I’ve observed is that it will first load a non AMP page and then after reloads to bring the AMP page. This only instance where this doesn’t happen is when it’s AMP-to-AMP linking. I tried to enable mobile server side redirection add_filter( 'amp_mobile_client_side_redirection', '__return_false' ); but it was loading AMP even on desktop versions and I removed the code.

    I added these two lines;
    amp_mobile_redirect
    amp-mobile-version-switcher

    in litespeed’s JS Excludes in litespeed cache but that doesn’t help either I don’t know if I have to add a .js on each of them in order to work. I also added this code
    `function amp_litespeed_compat() {

    if ( function_exists( ‘amp_is_request’ ) && amp_is_request() ) {
    define( ‘LITESPEED_BYPASS_OPTM’, true );
    add_filter( ‘litespeed_can_optm’, ‘__return_false’ );
    }

    }

    add_action( ‘wp’, ‘amp_litespeed_compat’ );`

    but it doesn’t seem to do any effect

    • This topic was modified 1 month, 2 weeks ago by iamlaurie.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter iamlaurie

    (@abanista)

    I have moved to standard mode. Hope it will solve my problem, and hoping it will leave the desktop version non AMP.

    Thread Starter iamlaurie

    (@abanista)

    I reverted bacj to transitional mode. Desktop version was serving amp too

    Plugin Support Milind More

    (@milindmore22)

    Hello @abanista

    Thank you for the support topic, The AMP plugin adds the mobile redirection script on non-AMP pages.

    The Litespeed cache plugin’s JS Combine and Defer feature adds that script in a single file and puts it on the footer, this delays mobile redirection.

    To fix this issue please add the following code snippet in your themes functions.php or in a custom plugin. the following code will add LiteSpeed exclusion attributes to AMP mobile redirection script.

    add_filter(
    	'wp_inline_script_attributes',
    	function ( $attributes, $source ) {
    		if ( false !== strpos( $source, 'amp_mobile_redirect_disabled' ) ) {
    			$attributes['data-no-defer']    = '1';
    			$attributes['data-no-optimize'] = '1';
    		}
    		return $attributes;
    	},
    	10,
    	2
    );

    Hope this helps!

    Plugin Support Milind More

    (@milindmore22)

    Hello @abanista

    just checking if the above code snippet helped you with slow redirection on your site.

    Thread Starter iamlaurie

    (@abanista)

    Hi @milindmore22

    Yes the code solved the issue. I wish it is added in the plugin core. Many thanks. My question is do I still need to have this code below or I should remove it

    function amp_litespeed_compat() {
    
    if ( function_exists( ‘amp_is_request’ ) && amp_is_request() ) {
    define( ‘LITESPEED_BYPASS_OPTM’, true );
    add_filter( ‘litespeed_can_optm’, ‘__return_false’ );
    }
    
    }
    
    add_action( ‘wp’, ‘amp_litespeed_compat’ );

    Also, do I still need these exclusions

    amp_mobile_redirect
    amp-mobile-version-switcher
    

    now that everything worked with the code you provided

    • This reply was modified 1 month, 1 week ago by iamlaurie.
    • This reply was modified 1 month, 1 week ago by iamlaurie.
    Plugin Support Milind More

    (@milindmore22)

    Glad our suggestion is helpful, I’ll mark this as resolved Open a new support topic if you face further issues, also feel free to leave a plugin review, we would love to hear your feedback.

    1) You do not need that code snippet, it was useful for the old Litespeed plugin versions (Litespeed plugin version that is below 4 )

    2) You don’t need to add any other exceptions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.