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.

Related:  Change Background for a Single WordPress Page
Continue Reading
You may also like...

We are a WordPress plugin developer company that focuses on useful WordPress plugin creation and empowering people to earn passive incomes from their blogs. We build unique and groundbreaking plugins that will revolutionize your blog!

Click to comment

Leave a Reply

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

More in solution

    Sign up for our newsletter and get a free affiliate e-book!

    About Me:

    Szabi Kisded

    Hi, my name is Szabi and I'm documenting my journey earning an online (semi)passive income. Learn more

    Mega Plugin Bundle:

    CodeCanyon Portfolio:

    Online Courses:

    Recommended Theme:

    Popular Posts:

    Latest Posts:

    To Top