Ways to minimize the performance impact of JavaScript

1. Put all script tags at the bottom of the page, just inside of the closing /body tag. This ensures that the page can be almost completely rendered before script execution begins.

2.Group scripts together. The fewer script tags on the page, the faster the page can be loaded and become interactive. This holds true both for script tags loading external JavaScript files and those with inline code.

3. There are several ways to download JavaScript in a nonblocking fashion:
a. Use the defer attribute of the script tag (Internet Explorer and Firefox 3.5+ only)
b. Dynamically create script elements to download and execute the code
c. Download the JavaScript code using an XHR object, and then inject the code into the page

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.