Search code examples
javascriptjquerytwitter-bootstrapasynchronouspagespeed

Async Javascript files that depend on order


When using PageSpeed Insights to evaluate the performance of my site, I get a 70/100, and the recommendation is that I should make jquery and bootstrap.js asynchronous to improve the performance.

enter image description here

The problem is that asynchronous scripts are not guaranteed to execute in specified order. I had a problem earlier that the button to expand the navbar menu doesn't work if jquery isn't loaded when bootstrap loads.

How can I enforce jquery to load before bootstrap but still get the benefits of async scripts?


Solution

  • You should take a look at: http://requirejs.org. This will allow you to call on the js files you need for each page and it is async already.