how to preload js file in amp + non amp post/pages?

Posted in: Newspaper
Post count: 11

I want to preload cdn.ampproject.org/v0.js into my website for better performance.

1) /applications/rmanupmumc/public_html/wp-content/plugins/td-composer/mobile/amp/functions.php

2) /applications/rmanupmumc/public_html/wp-content/plugins/td-composer/mobile/functions.php

======== my code – start ==========
function dns_prefetch_mobile() {

echo “<link as=script href=https://cdn.ampproject.org/v0.js rel=preload>”;
}

add_action( ‘wp_head’, ‘dns_prefetch_mobile’, 0 );
======== my code – end ==========

I have placed the above code in both above locations but the code is not working. I have put the above code in both the files one by one but js file is not preloaded.

I am using the latest version of the newspaper theme (11.2). can you please help me?

waiting for your response.

Post count: 18283

Hello!

That can be done using external plugins. WP-Rocket or Autoptimize is what a lot of our users use to use.

Thank you!

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.