Categories
Technology

How to Optimize Amazon Affiliate JS with LiteSpeed Cache WordPress Plugin

Did you enable ‘Load JS Deferred‘ in the LiteSpeed Cache Page Optimization, WordPress Plugin? I don't believe the Amazon Affiliate JS likes being deferred. Trust issues? Optimize Amazon Affiliate JS with LiteSpeed:

Go to LiteSpeed Cache => Page Optimization => [7] Tuning Settings

Scroll down until you see ‘JS Deferred Excludes'.

Add a line like:

 z-na.amazon-adsystem.com/widgets/onejs

Go to LiteSpeed Cache => Page Optimization => [3] Optimization Settings

Scroll down until you see ‘DNS Prefetch'.

Add a line like:

//z-na.amazon-adsystem.com

Go to LiteSpeed Cache => Toolbox => [1] Purge (default) => Click on Empty Entire Cache

Clears all cache entries related to your site, including other web applications. This should only be used if things are cached incorrectly.

If you also use Cloudflare Rocket Loader, you need to change your code:

<script type="text/javascript">
amzn_assoc_tracking_id = "YourAmazonTrackingID";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_design = "enhanced_links";
amzn_assoc_asins = "B08JGX61H7";
amzn_assoc_placement = "adunit";
amzn_assoc_linkid = "048bc2065ee4ca44aa99035a2a844837";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>

TO:

<script data-cfasync="false" type="text/javascript">
amzn_assoc_tracking_id = "YourAmazonTrackingID";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_design = "enhanced_links";
amzn_assoc_asins = "B08JGX61H7";
amzn_assoc_placement = "adunit";
amzn_assoc_linkid = "048bc2065ee4ca44aa99035a2a844837";
</script>
<script data-cfasync="false" src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>

This fixed my website. Hopefully it helps someone else from having to disable JD Deferred completely and lose the performance benefits of the optimization.

Special Thanks

TESMAT at Tesla Supercharger

TESMAT

TESMAT could be the right mattress for your next Supercharger nap, car camping trip, or the perfect gift for your favorite Tesla Model 3/Y owner. You can use my coupon code to save on your purchase.

Learn more:

How to Optimize Amazon Affiliate JS with LiteSpeed Cache WordPress Plugin 1

Luminar AI

Use the button below and feel free to use the discount code (GRAYDON) to give yourself a 10% discount at checkout on Luminar:

I may earn a small commission for my endorsement, recommendation, testimonials and / or links to products or services linked above. Your purchase supports me in bringing you more photographs, travel guides, and more trips around the world.

By Graydon Schwartz

Find out more about Graydon on the About Me page.