Creating a custom dependency block

64 Views Asked by At

I'm currently trying to load in multiple JS dependencies into a page. As per best practice etc I'm loading in my JS at the bottom of the page, but I have a particular JS file that I need to load in the head.

How would I go about making a block that only loads in this particular dependency in the <head> but the other JS files carry on loading in the bottom of the page?

1

There are 1 best solutions below

0
On

This particular case happens in Yoeman's webapp generator where it loads Modernizr in the head and the rest of the scripts near the bottom. If you problem is that the dependency you are facing is being injected at the bottom then you have to exclude it using the following:

wiredep: {
  app: {
    ....
    exclude: [
      'bower_components/path-to-the-file-you-dont-want-wiredep-to-inject'
    ],
  }
}

And in your head add the following:

  <!-- build:js scripts/vendor/custom-script.js -->
  <script src="bower_components/path-to-the-file-you-dont-want-wiredep-to-inject"></script>
  <!-- endbuild -->