Make sure a specific script loads before another script

I can’t understand how the scripts load on the page. I have jQuery plugins that depend on other scripts. I am using the timeago jQuery plugin. I loaded this script into my head in order:

<script src="<?php echo base_url().'content/scripts/jqueryEngine/jquery.js' ?>" type="text/javascript"></script> //jquery library <script src="<?php echo base_url().'content/scripts/timeago.js' ?>" type="text/javascript"></script> //timeago <script src="<?php echo base_url().'content/scripts/myscript.js' ?>" type="text/javascript"></script> // Custom scripts that contains ajax. 

And in document ready I initialize timeago. But this does not work for me. In the console, the browser shows that timeago is not working. I want to make sure timeago is already loaded before running any other script. My scripts also contain several Ajax calls that rely on timeago.

+6
source share
1 answer

The order of the script tags in your HTML basically determines the loading order of your scripts. So, you already have this setting.

A few questions to help you debug your problem:

  • Take a look at the developer console to see if the time has really been loaded back? or you got 404
  • Are there any error messages in the developer console? this makes applications not work as expected.

Based on the comments below, it seems that the file is not loading by the browser, and you should be able to debug things like this using the Chrome developer tools.

0
source

Source: https://habr.com/ru/post/986400/


All Articles