Common JavaScript errors

What happens when an external JavaScript file fails to load?

JavaScript is mainly used to make web pages interactive and dynamic. To do this, you can embed the code directly into the page or store it in an external file and link to it. The second method shortens the loading time. It also makes maintenance easier, because you only have one file and one link to that file.

To include external JavaScript files, you use the script element:

<script src="name.js"></script>

In the same way, you can also link JavaScript files on other web servers by noting the URL in the ‘src’ attribute. However, unloaded external JavaScript files can make pages unusable. This is especially true for web pages that rely heavily on JavaScript.

Therefore, you should make sure that the link is spelt correctly and that the file path or URL is correct. Ideally, save the JavaScript file as a text document with the extension .js.

Attention: Do not use any script elements in the JavaScript file itself!

How many JavaScript files should you load on a page?

Many external JavaScript files that have to be requested during a page load slow down the loading time. This worsens usability and you use more crawling resources than necessary. Therefore: Less is more.

If possible, only use JavaScript files that offer visitors real added value. Ideally, you should combine all JavaScripts in a single file that is loaded only once. This should be an external JavaScript file integrated at the end of the source code.

What happens when a JavaScript file redirects to another file?

Client-side redirects via JavaScript have the advantage that they can be implemented quickly and easily. The catch is that some browsers don’t support JavaScript and some users don’t have it enabled. Both lead to the fact that the redirection cannot be executed.

It can even happen that bots falsely impersonate browsers. In addition, client-based redirection has disadvantages for indexing because the redirection domain can compete with the target domain. Finally, unlike server-side redirects, there is a noticeable delay. For these reasons, client-side redirects via JavaScript should be treated with caution.

What happens if a JavaScript file cannot be found?

JavaScript is primarily used to include interactive elements in web pages. Depending on how important these are for a page, JavaScript files that cannot be found can result in the web page being only partially usable or no longer usable. This is the case with YouTube, for example. Here, without JavaScript, nothing remains of the original look and functionality.

YouTube with JavaScript disabled

To avoid this situation with your own page, make sure that JavaScript files are accessible and that the URL or path in your script element is correct. If you want to know if your page works without JavaScript, you can test it with the Chrome Dev Tools.

Steve Paine