Why Implementing “Defer Javascript” on a Website Is a Good Idea

Page load times are important in the user experience. This is particularly true if someone finds it through a search engine result. If your page takes too much time to load, then an impatient user might not want to wait and immediately hit the back button on the browser. This not only deprives you of one more potential customer; it also increases your bounce rate, which will likely negatively affect you ranking potential in Google.

One reason pages can take a long time to load is the presence of a lot of JavaScript code in the header of the site. JavaScript is a simple programming language commonly used to implement additional functionality in html pages. For example, it can be used to execute conditional statements, such as returning an error if a certain form is not filled out correctly. You know the kind of thing – when you’ve forgotten to add your ZIP code or your email address is the wrong format. Adding a bit of JavaScript to such a form can help someone see what they’re not entering correctly.

The problem with JavaScript is if there is too much of it on a page, it can take a lot longer for a page to run. Each piece of JavaScript must be downloaded separately, and most browsers have a limited amount of throughput in the number of files they can download at the same time. The browser must then interpret the code. Since most JavaScript is loaded in header files, this code must be processed before much of the actual page is actually rendered. This leaves the user staring at an unfinished page in the interim. This has become particularly problematic as WordPress users have started using more and more plugins, each of which usually places additional JavaScript code in a header.

However, most JavaScript is not needed until after the page is rendered. One can actually place one more piece of JavaScript in the header that actually tells the browser to deal with the subsequent JavaScript after it has finished rendering the page. This “defer JavaScript” code can thus dramatically improve page load times along with the user experience.

Page load times are important for your website and if your page is loading slowly, it could be a result of a problem with excessive JavaScript. As a result, implementing ‘defer JavaScript’ code in your website headers can significantly cut down on the time to render the page in a browser. As such this is one method of speed optimization that you can implement to make your website faster.