Connect with us

Security: Do not add 3rd party JavaScript code in header


Security: Do not add 3rd party JavaScript code in header

If you place third party JavaScript codes in your HTML head, you are effectively giving up control of site at the mercy of the third party. Your site will not load if the third party server is no-responsive or simply dead.

With exception of Google, which you don’t expect it to go offline (also you are required to do so), third party JavaScript codes should be in the footer.

One of our sites once trial-tested a free theme which used a third party JavaScript hosted with a CDN. One morning, the site just stopped dead trying to load the JavaScript. The story was that the CDN server name has been changed as the said CDN company was acquired by a larger company. The good thing was the site was still in development and with further investigation, we ended up using a CDN ourselves. But this should not be happening to your site. Period.

Web browsers download page elements in the order that they are listed in your HTML – CSS, JavaScript, and images (mostly). If the domain that any of those are hosted on is offline or going slow, a web browser will “hang” for up to 60 seconds while it waits for the item to load, before moving on to the next item. (Asynchronous JavaScript is an exception but that’s still not very common – although we do offer it an option – but again, that’s not the point. And besides, if you’re loading it asynchronously, you’re not depending on it being available for immediate execution, so what would be the point of putting it in your HTML head?).

If you have third party JavaScript in your HTML head and that third party server goes offline, your web site is effectively dead because nothing else is going to load for up to 60 seconds. When I visit sites that hang like that, I immediately close them as I’m sure 99% of people do.

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in solution

    About Me:

    Szabi Kisded

    Hey there, I'm Szabi. At 30 years old, I quit my IT job and started my own business and became a full time WordPress plugin developer, blogger and stay-at-home dad. Here I'm documenting my journey earning an online (semi)passive income. Read more

    Sign up for my newsletter and get the YouTube Caption Scraper WordPress plugin for free
    (worth 29$)!

    All My Plugins In A Bundle:

    My AutoBlogging Plugins:

    My Online Courses:

    A Theme I Recommend:

    Featured Posts:

    To Top