Resolving Legacy JavaScript Warnings and Performance Issues in Ad Inserter
Content
Many users of the 'Ad Inserter – Ad Manager & AdSense Ads' plugin encounter warnings in tools like Google PageSpeed Insights, GTmetrix, or Lighthouse. A common message is "Avoid serving legacy JavaScript to modern browsers," often pointing to functions like Array.prototype.includes or Number.isInteger within the plugin's scripts. Other users report large inline JavaScript blocks or unnecessary external script loads impacting their site's performance metrics. This guide explains why these happen and how to address them.
Why These Warnings and Performance Issues Occur
The 'Ad Inserter – Ad Manager & AdSense Ads' plugin includes JavaScript code for its client-side functionality. This code is designed to be compatible with a wide range of browsers, including older ones. To achieve this, the plugin's scripts sometimes include polyfills—code that implements modern JavaScript features (like Array.prototype.includes) in older browsers that don't natively support them. Performance tools flag this code as "legacy" because modern browsers already have these features built-in, making the polyfills unnecessary for them.
Furthermore, features like ad-blocking detection, tracking, and certain insertion methods (e.g., After HTML element) require this client-side JavaScript. By default, the plugin is often configured to output this code directly into your page's HTML (inline) for reliability, which can increase the page's HTML size. Enabling options like external scripts for ad-blocking detection can also trigger requests to external domains, which might be flagged or cause timeouts.
Common Solutions and Workarounds
1. For Legacy JavaScript Warnings (PageSpeed, Lighthouse)
Understanding the Message: The development team for 'Ad Inserter – Ad Manager & AdSense Ads' has stated these warnings are typically a false positive from performance tools. The code is not faulty; it's a compatibility measure. In many cases, you can safely ignore these warnings if they are not causing actual functionality problems for your site's visitors.
If You Want to Pursue a Fix: The warnings are often tied to specific plugin functions. Try the following:
- Disable the Tracking feature for any blocks where it is enabled, as this can trigger the
Number.isIntegerwarning. - Avoid using client-side insertion modes like After HTML element, Before HTML element, or Inside HTML element if possible, as these can trigger the
Array.prototype.includeswarning. Use server-side insertion methods instead. - As a test, try completely resetting the plugin's settings to see if the warning disappears. Then, re-enable your configuration one feature at a time to identify the exact culprit.
2. For Large Inline JavaScript Blocks
The large block of JavaScript code that starts with ai_front = is loaded for client-side functions. To reduce HTML size:
- Go to Ad Inserter Settings → Javascript code.
- Change the option from Inline to File. This will cause the plugin to load the necessary code from an external JavaScript file (
/wp-content/plugins/ad-inserter/js/ai-functions.js) instead of printing it all inline. This can be more efficient for caching. - Important: If you use a performance plugin that lazy-loads or defers JavaScript, you may need to exclude this file (
/ad-inserter/js/(.*).js) from those optimizations to prevent conflicts with ad display.
3. For Unnecessary Script Loading
If you see scripts loading on pages where you don't serve ads, or scripts from ad-blocking detection are causing issues:
- To disable ad-blocking detection on specific pages, you can use the shortcode
[adinserter adb="disabled"]in the page content. - You can disable individual elements for ad-blocking detection in the plugin's settings under the ad-blocking troubleshooting section.
- If you are not using ad-blocking detection at all, ensure it is completely disabled in the plugin settings to prevent any related scripts from loading.
4. For jQuery Loading
If you want to prevent the plugin from loading jQuery, navigate to Ad Inserter Settings → Wait for jQuery and disable this option. Be aware that this may break client-side features that depend on jQuery.
Conclusion
Performance tool warnings related to 'Ad Inserter – Ad Manager & AdSense Ads' are often related to its built-in browser compatibility code. While usually safe to ignore, you can mitigate them by adjusting your use of client-side features like tracking and specific insertion modes. For perceived performance issues, switching JavaScript output from inline to a file and carefully managing ad-blocking detection settings can help optimize your site's load time without losing functionality.
Related Support Threads Support
-
Information: Legacy JavaScript code used, disable Wait for jQueryhttps://wordpress.org/support/topic/information-legacy-javascript-code-used-disable-wait-for-jquery/
-
code for ad blocking detectionhttps://wordpress.org/support/topic/code-for-ad-blocking-detection/
-
Avoid serving legacy JavaScript to modern browsershttps://wordpress.org/support/topic/avoid-serving-legacy-javascript-to-modern-browsers-14/
-
page may not be loaded properly ,Check blocking software that may block CSS,Javahttps://wordpress.org/support/topic/page-may-not-be-loaded-properly-check-blocking-software-that-may-block-cssjava/
-
Why is Ad Inserter still loading jQuery?https://wordpress.org/support/topic/why-is-ad-inserter-still-loading-jquery/
-
Avoid serving legacy JavaScript to modern browsershttps://wordpress.org/support/topic/avoid-serving-legacy-javascript-to-modern-browsers-4/
-
f.txt Download Problemhttps://wordpress.org/support/topic/f-txt-download-problem/
-
Load ad scripts staticallyhttps://wordpress.org/support/topic/load-ad-scripts-statically/
-
Lots of inline js added for nothinghttps://wordpress.org/support/topic/lots-of-inline-js-added-for-nothing-2/
-
Ad Inserter adding Inline js or ai-functions.min.jshttps://wordpress.org/support/topic/ad-inserter-adding-inline-js-or-ai-functions-min-js/
-
Pagespeed shows Minify CSShttps://wordpress.org/support/topic/pagespeed-shows-minify-css/
-
Ad is not showing Due to jquery error when using swift Performance Pluginhttps://wordpress.org/support/topic/ad-is-not-showing-due-to-jquery-error-when-using-swift-performance-plugin/
-
Jquery Loadhttps://wordpress.org/support/topic/jquery-load/
-
Avoid serving legacy JavaScript to modern browsershttps://wordpress.org/support/topic/avoid-serving-legacy-javascript-to-modern-browsers-11/
-
Information req: JavaScripts Used by Ads Inserterhttps://wordpress.org/support/topic/information-req-javascripts-used-by-ads-inserter/
-
Lighthouse audit legacy javascript warninghttps://wordpress.org/support/topic/lighthouse-audit-legacy-javascript-warning/
-
Javascript slowing page downhttps://wordpress.org/support/topic/javascript-slowing-page-down/
-
Lots of Unnecessary Inline Scripts Addedhttps://wordpress.org/support/topic/lots-of-unnecessary-inline-scripts-added/
-
getting Message related to “Wait for jQuery”https://wordpress.org/support/topic/getting-message-related-to-wait-for-jquery/
-
Why Quantserve.com Script is injected after enabling the Ad Blocking Feature?https://wordpress.org/support/topic/why-quantserve-com-script-is-injected-after-enabling-the-ad-blocking-feature/
-
Can you set these codes not to be displayed?https://wordpress.org/support/topic/can-you-set-these-codes-not-to-be-displayed/
-
define (‘AI_CONTENT_MARKER’, ‘AI CONTENT END’);https://wordpress.org/support/topic/define-ai_content_marker-ai-content-end/
-
Lots of inline js added for nothinghttps://wordpress.org/support/topic/lots-of-inline-js-added-for-nothing/
-
Disable the ad blocking script on selected pageshttps://wordpress.org/support/topic/disable-the-ad-blocking-script-on-selected-pages/
-
Which JavaScript is used (for lazy loading)https://wordpress.org/support/topic/which-javascript-is-used-for-lazy-loading/
-
About [Avoid serving legacy JavaScript to modern browsers] issue?https://wordpress.org/support/topic/about-avoid-serving-legacy-javascript-to-modern-browsers-issue/
-
Cannot load https://contextual.media.net/dmedianet.jshttps://wordpress.org/support/topic/cannot-load-https-contextual-media-net-dmedianet-js/
-
Ad code showing 8 times leading to large page sizehttps://wordpress.org/support/topic/ad-code-showing-8-times-leading-to-large-page-size/