Ik heb deze code uitgeprobeerd: http://idiallo.com/javascript/async-jquery
maar ik krijg nog foutmeldingen dat jquery niet geladen is als dit:




2017-04-05 09:59:14.198 jquery.validate.min.js:4 Uncaught ReferenceError: jQuery is not defined
    at jquery.validate.min.js:4
    at jquery.validate.min.js:4
(anonymous) @ jquery.validate.min.js:4
(anonymous) @ jquery.validate.min.js:4
2017-04-05 09:59:14.202 jquery.mmenu.min.all.js:13 Uncaught ReferenceError: jQuery is not defined
    at jquery.mmenu.min.all.js:13
(anonymous) @ jquery.mmenu.min.all.js:13
2017-04-05 09:59:14.204 unslider-min.js:1 Unslider needs jQuery
(anonymous) @ unslider-min.js:1
(anonymous) @ unslider-min.js:1
2017-04-05 09:59:14.226 jquery-ui.min.js:5 Uncaught ReferenceError: jQuery is not defined
    at jquery-ui.min.js:5
(anonymous) @ jquery-ui.min.js:5
2017-04-05 09:59:14.228 tooltipsy.min.js:20 Uncaught ReferenceError: jQuery is not defined
    at tooltipsy.min.js:20
(anonymous) @ tooltipsy.min.js:20
2017-04-05 09:59:14.288 (index):7580 jquery main script is ready




Dus in mijn footer heb ik


<script>                
var async = async || [];
(function () {
  var done = false;
  var script = document.createElement("script"),
  head = document.getElementsByTagName("head")[0] || document.documentElement;
  script.src = '<?=HTML_ROOT?>js/jquery-1.12.4.min.js';
  script.type = 'text/javascript'; 
  script.async = true;
  script.onload = script.onreadystatechange = function() {
      if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
          done = true;
          console.log('jquery main script is ready');
          // Process async variable
          //var async = async || [];
          while(async.length) { // there is some syncing to be done
              var obj = async.shift();
              if (obj[0] =="ready") {
                  $(obj[1]);
              }else if (obj[0] =="load"){
                  $(window).load(obj[1]);
              }
          }
          async = {
              push: function(param){
                  if (param[0] =="ready") {
                      $(param[1]);
                  }else if (param[0] =="load"){
                      $(window).load(param[1]);
                  }
              }
          };
          // End of processing
          script.onload = script.onreadystatechange = null;
          if (head && script.parentNode) {
              head.removeChild(script);
          }
      }
  };
head.insertBefore(script, head.firstChild);
})();
</script>


    <?php
    require_once(DOC_ROOT.'js/headerjs.php');
	?>
           
     <script defer async src="<?=HTML_ROOT?>js/jquery-ui.js"></script>		        
    <script defer async type="text/javascript" src="<?=HTML_ROOT?>js/jquery.validate.min.js"></script>
	<script defer async type="text/javascript" src="<?=HTML_ROOT?>js/jquery.mmenu.min.all.js">  </script> 
   
    	
    <script defer  async src="<?=HTML_ROOT?>js/unslider-min.js" type="text/javascript"></script>
     <script defer async src="https://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
      <script defer async src='<?=HTML_ROOT?>js/tooltipsy.min.js'></script>
    <script defer async src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
    
    <script async src="<?=HTML_ROOT?>js/script.js" defer></script>
    <script async src="<?=HTML_ROOT?>js/markerclusterer.js" defer></script> 



Waarom werkt dit niet?

Reageren