Title: Async? Defer?
Last modified: May 31, 2021

---

# Async? Defer?

 *  Resolved [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/)
 * Hey,
    Page optimization test show upload high, I see a couple of threads with
   a solution but I didn’t understand where to put this function.php: [https://gist.github.com/wtmujeebu/a6211941378345f980ad0201b70328cf](https://gist.github.com/wtmujeebu/a6211941378345f980ad0201b70328cf)
 * and have this too:
    [https://gist.github.com/wtmujeebu/a941b8bff26a4239fe0b60d8de30d285](https://gist.github.com/wtmujeebu/a941b8bff26a4239fe0b60d8de30d285)
 * I didn’t understand what is better and how to implant them.
 * btw I have Autoptimize, maybe is possible to do it with a cache plugin and save
   
   trouble.
 * please help 🙂
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fasync-defer%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [WebToffee](https://wordpress.org/support/users/webtoffee/)
 * (@webtoffee)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14505403)
 * Hi [@123nadav](https://wordpress.org/support/users/123nadav/),
 * You can add it directly in your active child theme’s functions.php file or you
   can use a plugin like **Code Snippets.**
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14510668)
 * is little problem “code snipet”
 * can put it as a script in the header and footer plugin? as a script and not php?
   
   and what better from the 2 links?
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14514088)
 * [@webtoffee](https://wordpress.org/support/users/webtoffee/) Please help? what
   is better?
    and if I can put a script and not PHP and a plugin of a “header and
   footer”?
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14514447)
 * jquery script for delay gets errors.
    you use jquery and this feature is deprecated
   from WordPress 5.5.5
 * the error:
    Uncaught ReferenceError: jQuery is not defined at VM119:266 (anonymous)
   @ VM119:266
 * when I remove your PHP script everything comeback normal
    you must provide new
   script to delay the pop up or async it
 *  Plugin Author [WebToffee](https://wordpress.org/support/users/webtoffee/)
 * (@webtoffee)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14515916)
 * HI [@123nadav](https://wordpress.org/support/users/123nadav/),
 * Please copy the below code to your active site theme’s functions.php towards 
   the last line.
 *     ```
       add_action('wp_footer', 'wt_cli_delay_cookie_banner', 10);
       function wt_cli_delay_cookie_banner()
       {
       	if (class_exists('Cookie_Law_Info')) {
       	?>
       		<script>
       			jQuery(function() {
       				var timeDelay = 3000; //Time in milli seconds, 1000 ms = 1 second.
       				CLI.bar_elm.hide();
       				if (CLI.settings.notify_animate_show) {
       					CLI.bar_elm.css('visibility', 'hidden');
       				}
       				setTimeout(function() {
       					if (!CLI_Cookie.read(CLI_ACCEPT_COOKIE_NAME)) {
       						if (CLI.settings.notify_animate_show) {
       							CLI.bar_elm.hide();
       							CLI.bar_elm.css('visibility', 'visible');
       							CLI.bar_elm.slideDown(CLI.settings.notify_animate_show);
       						} else {
       							CLI.bar_elm.show();
       						}
       					}
       				}, timeDelay);
       			});
       		</script>
       <?php
       	}
       }
       ```
   
 * To fix the error in console, add below code too to functions.php
 *     ```
       add_filter('autoptimize_filter_js_exclude','jquery_toggle');
       function jquery_toggle($in) {
           if ( is_single() ) {
               return $in.',js/jquery/jquery.js';
           }
           else {
               return $in;
           }
       }
       ```
   
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14518523)
 * [@webtoffee](https://wordpress.org/support/users/webtoffee/) still have errors:
   
   [https://locksmithunit.com](https://locksmithunit.com) I put them in the Code
   Snippets plugin you recommended to me. I put them in the order you tell me… what
   to do? Still got VM error with jquery
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14518652)
 * I don’t think it will work properly…
    you create PHP of time delay… **Is not 
   async**… the script still goes up and holds all the system to be executed…
 * I test the optimized CSS… is not good as well (don’t have errors, but nothing
   not happened to the CSS or don’t have any improvement)
 * bro you need to work on your plugin…
    You must optimize your plugin, is heavy,
   very heavy, site goes down in pagespeed very bad…
 * no option to control the script with DEFER or ASYNC.
 * your plugin is Super useful and must be on any website.
    but optimization is 
   very bad bro, even the PHP you created in Github. very bad.
 * this is not optimized for google or for any kind of website.
 *  Plugin Author [WebToffee](https://wordpress.org/support/users/webtoffee/)
 * (@webtoffee)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14519356)
 * Hi [@123nadav](https://wordpress.org/support/users/123nadav/),
 * You collected that code from [this thread](https://wordpress.org/support/topic/delay-showing-banner-with-animation/)
   and the requester of that thread was asking about how to implement the delay.
   So the solution would be to address that. You may please remove that code.
 * To add defer attribute, we have developed another code. Kindly try adding [this code](https://gist.github.com/webtoffee-git/6b136580dd7508b6ce486fda1a73ac39)
   via Code Snippets plugin. Add it a new snippet and activate.
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14520973)
 * the defer code working.
    but still is slow… you need to use ASYNC is much better.
 * if you developed new code with ASYNC i be very glad.
 * another thing is the CSS-optimized cookies:
    [https://gist.github.com/wtmujeebu/a941b8bff26a4239fe0b60d8de30d285](https://gist.github.com/wtmujeebu/a941b8bff26a4239fe0b60d8de30d285)
   I can add this as well to the snippet plugin?
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14521474)
 * The defer not help in the speed of the site…
    I think it needs to be a script
   going on the footer maybe.
 * you can test by yourself:
    locksmithunit.com
 * and identical site in Spanish without the script:
    locksmithunit.es
 * [https://developers.google.com/speed/pagespeed/insights/](https://developers.google.com/speed/pagespeed/insights/)
 * you can test by yourself you look don’t have any different.
 * this because you do not use async.
    or “function” him in the footer maybe?
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14525287)
 * Very bad.
    your plugin slows the site… but seriously… you must do something about
   the plugin… is insane.
    -  This reply was modified 5 years ago by [Nadav Levi](https://wordpress.org/support/users/123nadav/).
 *  Plugin Author [WebToffee](https://wordpress.org/support/users/webtoffee/)
 * (@webtoffee)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14526484)
 * Hi [@123nadav](https://wordpress.org/support/users/123nadav/),
 * Thank you for your feedback and apologies for the inconvenience caused. Some 
   performance improvements are already in our plans, so stay tuned for plugin updates.
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14526618)
 * [@webtoffee](https://wordpress.org/support/users/webtoffee/)
    your plugin is 
   very good to the GDPR. But the scripts run and the PHP is insane…
 * before that, I was with a pop-up CDN.
    if you want I can provide you the code.
 * I actually was thinking to save your plugin but remove the pop-up himself.
    (
   and put script from my own):
 * `<link rel="stylesheet" type="text/css" href="/cookieconsent.min.css"/><script
   src="https://cdn.wpcc.io/lib/1.0.2/cookieconsent.min.js" defer></script><script
   >window.addEventListener("load", function(){window.wpcc.init({"colors":{"popup":{"
   background":"#222222","text":"#ffffff","border":"#f9f9f9"},"button":{"background":"#
   f9f9f9","text":"#000000"}},"position":"bottom","content":{"href":"https://locksmithunit.
   es/politica-de-privacidad/","message":"Este sitio web utiliza cookies. Al continuar
   navegando por el sitio web, acepta nuestro uso de cookies. Más información:","
   link":"Politica de Cookies"},"padding":"none","corners":"small","margin":"small","
   transparency":"10","fontsize":"tiny","border":"thin"})});</script>``
 * possible to do stuff like this?
    and hide your popup? maybe to add a shortcode
   from your plugin to my popup? (combine them somehow)
 * my pop up is very fast, but your plugin is cover much more GDPR CCPA rules (help
   SEO).
 * Please help
 *  Thread Starter [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * (@123nadav)
 * [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14530790)
 * [@webtoffee](https://wordpress.org/support/users/webtoffee/) please tell me if
   i can use my script with your shortcode.
 * and if you can provide a PHP for the snippet plugin for removing your pop-up.
   (
   but to keep the plugin active! is very good plugin)
 * i do it because my pop up much more lighter.

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘Async? Defer?’ is closed to new replies.

 * ![](https://ps.w.org/cookie-law-info/assets/icon.svg?rev=3007243)
 * [CookieYes – Cookie Banner for Cookie Consent (Easy to setup GDPR/CCPA Compliant Cookie Notice)](https://wordpress.org/plugins/cookie-law-info/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cookie-law-info/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cookie-law-info/)
 * [Active Topics](https://wordpress.org/support/plugin/cookie-law-info/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cookie-law-info/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cookie-law-info/reviews/)

 * 14 replies
 * 2 participants
 * Last reply from: [Nadav Levi](https://wordpress.org/support/users/123nadav/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/async-defer/#post-14530790)
 * Status: resolved