• Home
  • About
  • Services
    • Technical SEO
    • Local SEO Services
  • Plugins & Scripts
  • Insights Hub
    • New Posts
    • Technical SEO
    • General Discussion
    • View All Forums
  • Blog
  • Contact
    • Hub
      New posts Search forums
    • What's new
      New posts New profile posts Latest activity
    • Members
      Current visitors New profile posts Search profile posts
    Log in Register
    What's new Search

    Search

    By:
    Advanced search…
    • New posts
    • Search forums
    Menu
    Log in

    Register

    Install the app
    • Home
      • Hub
      • Technical SEO
      You are using an out of date browser. It may not display this or other websites correctly.
      You should upgrade or use an alternative browser.

      Delay Execution of JS Scripts with JavaScript

      • Thread starter Chris
      • Start date Sep 12, 2021
      • Sep 12, 2021
      Improve your Google Pagespeed Insights score by delaying the execution of below-the-fold third-party functionality such as commenting scripts, help bots, reCAPTCHA, Share This, Cookie Scripts, and more.

      Async and Defer can really make a massive difference in improving Pagespeed Insights score, to go that extra mile to achieve a higher Pagespeed Insights score (PSI), try this.

      Delay the JS script execution
      Code:
      <script>
      setTimeout(function(){
      loadJs("third-party-script.js");
      },5000);
      </script>

      This script delays "third-party-script.js" for 5000 milliseconds, allowing plenty of time for all the async and defer scripts to load.

      Load after everything else
      Code:
      <script>
      window.onload = function() {
      loadJs("third-party-script.js");
      }
      </script>

      This script will fire after everything else has loaded.

      And lastly, the jQuery DomReady snippet.
      Code:
      <script>
      define(['jquery','domReady!'], function($) {
      
      // Your Code
      
      }(jQuery)
      );
      </script>

      Either of these options will help to improve your Google Pagespeed Insights score. I cannot confirm though if they will improve your Core Web Vitals. I need to gather more data. I will update this post accordingly.
       
      Click to expand...
      C
      Written by

      Chris

      Administrator
      Staff member
      • Messages
        57
      • Reaction score
        0
      • Points
        6
      You must log in or register to reply here.
      Share:
      Facebook Twitter Reddit Pinterest Tumblr WhatsApp Email Share Link

      New Posts

      • C
        Installing FFmpeg on CentOS
        • Started by Chris
        • Jul 29, 2022
        • Replies: 0
        General Discussion
      • C
        Complete list of Screaming Frog Pagespeed API Diagnostics & Metrics
        • Started by Chris
        • Jul 27, 2022
        • Replies: 0
        Technical SEO
      • C
        Run Screaming Frog in the Cloud on Windows Server
        • Started by Chris
        • Jul 1, 2022
        • Replies: 0
        Technical SEO
      • C
        Nofollow Link Highlighter - Free Chrome Browser Extension
        • Started by Chris
        • Jun 15, 2022
        • Replies: 1
        Blog
      • C
        Hide The Ads Google Chrome Extension
        • Started by Chris
        • May 26, 2022
        • Replies: 0
        Blog
      • C
        Hide People Also Asked (PAA) Google Chrome Extension
        • Started by Chris
        • May 24, 2022
        • Replies: 0
        Blog
      • C
        Dropped .UK Domains 11th April 2022
        • Started by Chris
        • Apr 11, 2022
        • Replies: 0
        General Discussion
      • C
        Google Sheets Regex for excluding subfolders
        • Started by Chris
        • Oct 12, 2021
        • Replies: 0
        Technical SEO
      • Hub
      • Technical SEO

    Join the Community

    Chris Lever is a freelance SEO Consultant availible for Hire. Join the growing SEO Community Forum to learn new skills.

    Join Us

    Need Help?

    • BB Code
    • Cookie Policy
    • Terms of Use
    • Privacy Policy
    • HTML Sitemap

    Learn More

    • About
    • Availability
    • Popular Posts
    • Projects & Scripts
    • Contact

    Get in Touch

    Chris Lever, Manchester, United Kingdom
    info@chrisleverseo.com
    +44 0161 883 2249

    © 2022 Chris Lever SEO. All rights reserved. Powered by Xenforo

    • This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
      By continuing to use this site, you are consenting to our use of cookies.
      Accept Learn more…