Yepnope is not working as expected

1.3k views Asked by At

I am using yepnope in my project .I want to load only needed js and css files in my page .But yep nope is not working as expected.

My codes are

$(document).ready(function(){
   yepnope([{
    // Load jquery from a 3rd party CDN
    load: 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',
    callback: function (url, result, key) {
      if (!window.jQuery) {
        yepnope('3rdparty/js/jQuery2.1.4.js');
      }
    }
  }]);
})

But it does not actually load What can be the possible solution?

1

There are 1 answers

1
taxicala On

I believe you are trying to use jquery before you actually load it with yepnope, try putting your script at the end of your DOM, just before closing the body tag as follows:

   yepnope([{
    // Load jquery from a 3rd party CDN
    load: 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',
    callback: function (url, result, key) {
      if (!window.jQuery) {
        yepnope('3rdparty/js/jQuery2.1.4.js');
      }
    }
  }]);

If you see, i've removed the document ready event because it's done by jquery, and you are loading jquery within your yepnope. Another thing, are you getting any error in your console? maybe $ is not defined ?