7

I can't get how the scripts in a page are loaded. I have jQuery plugins that depend on other scripts. I am using the timeago jQuery plugin. I have loaded this script in 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 am initializing timeago. But this is not working for me. In the console, the browser shows timeago is not functioning. What I want is to ensure that timeago has already loaded before any other script runs. My scripts also contains multiple Ajax calls that rely on timeago.

dda
  • 6,030
  • 2
  • 25
  • 34
user254153
  • 1,855
  • 4
  • 41
  • 84

1 Answers1

1

The order of the script tags in your HTML basically determines the order of your scripts loading. So you have that setup correctly already.

A couple of points to help you debug your issue:

  • Look at the developers console to see if time ago is actually loaded? or did you get a 404
  • Still in the developer console, are there any errors reported? these cause your applications to not run as expected.

Based on the comments below, it seems that the file is not being loaded by the browser, and you need to be able to debug things like this using the chrome developer tools.

filype
  • 8,034
  • 10
  • 40
  • 66
  • The only error is timeago function not define. All things are same. And I had included in question that my scripts contains ajax function which is calling timeago function on success. As ajax is asynchronous it may execute before timeago plugins. So I need to load timeago plugins before ajax gets success. – user254153 May 02 '15 at 08:37
  • Are you using https://github.com/rmm5t/jquery-timeago? is it that the file should be names `jquery-timeago.js` instead? – filype May 02 '15 at 08:38
  • If your ajax calls are wrapped in `$(document).ready` then it will run as expected – filype May 02 '15 at 08:39
  • Yes this is what I am using. – user254153 May 02 '15 at 08:46
  • @user254153 - this jquery plugin won't expose timeago in the browser. what happens when you type this in the developer console? `$.fn.timeago` - you should see the timeago function – filype May 02 '15 at 08:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76752/discussion-between-filype-and-user254153). – filype May 02 '15 at 08:59