Home > General Web Development > Load JavaScript File Dynamically

Load JavaScript File Dynamically

So you have been programming with JavaScript? Usually programmers write the JavaScript code in the header of the HTML page or load it externally:

But sometimes there is no need to load some of the JavaScript codes because it won’t be used on the page. That will waste you unnecessary bandwidth and will cost your website users their precious time.

The solution is to load the JavaScript file dynamically only when is required. Ed Eliot posted an article shows how load a JavaScript dynamically. However, loading the JavaScript file asynchronously causes some problems when calling a function written in the loading file. Ed Eliot has written his idea on how to solve this overwhelming problem. He simply uses the event handling to check whether the file finished loading or not. Read more about this in his article.

Categories: General Web Development Tags:
  1. No comments yet.
  1. No trackbacks yet.