shinsenter / defer.js

🥇 A lightweight JavaScript library that helps you lazy load (almost) anything. Defer.js is dependency-free, highly efficient, and optimized for Web Vitals.
https://shinsenter.github.io/defer.js/
MIT License
277 stars 44 forks source link

$ is not defined #33

Closed yanivz closed 5 years ago

yanivz commented 5 years ago

Describe the bug page breaks and not working good when jquery in page To Reproduce every occurence of jquery $ sign got error

shinsenter commented 5 years ago

@yanivz which version of defer.js are you using?

shinsenter commented 5 years ago

Closed this issue

danielrob commented 5 years ago

Is there any better pattern to solve dependency trees than callbacks?

  deferscript("jQuery", false, 80, function() {
    deferscript("slickSlider", false, 0, function() {
      deferscript("balanceText", false, 0, function() {
    });
  });

@yanivz you have a number of options to my naive knowledge:

if (jQuery) { dependentScript(jQuery) } else { window.jQueue = window.jQueue || [] window.jQueue.push(dependentScript) }