Javascript includes not loading for later in the page

前端 未结 7 2530
我寻月下人不归
我寻月下人不归 2021-02-20 08:42

We have a Rails application where we are including our application dependencies in the html head within application.js:

//= require jquery
//= requi         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-20 08:59

    It has a cool solution. Make js loading correctly for your application. Here, I am loading jQuery first then loading analytics.js . I hope this will solve your problem for html5 supported browsers. Code:

        var fileList =[
                        'your_file_path/jQuery.js',
                        'your_file_path/analytics.js'
                      ];
    
        fileList.forEach(function(src) {
        var script = document.createElement('script');
        script.src = src;
        script.async = false;
        document.head.appendChild(script);
     });
    

    This code snippet will load jQuery first and then load analytics.js file. Hopefully, this will fix your issue.

提交回复
热议问题