1

Today i figured out that other the "standard way" to include jquery and jqueryui:

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

There is another way, with the google jsapi:

<script src="//www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.4.2");
google.load("jqueryui", "1.7.2");
$(function() { $( document ).tooltip(); });
</sciprt>

Is the jsapi method better?

Because i've tried the jsapi method but it seems that only works with jquery and doesn't work with jqueryui, in fact the tooltip is not shown. What's wrong? Should I include the jquery css too? or maybe I need a key?

Captain John
  • 1,859
  • 2
  • 16
  • 30
ipel
  • 1,326
  • 1
  • 18
  • 43
  • 1
    Because you are using jsapi and it loads javascript async way when you are trying to use jQuery there is no guarantee that jquery and jqueryUI will be loaded. When using script tags nothing will be executed until the file is loaded. There is an option with `load` which allows you to trigger a callback so that you can execute your code when the library you requested is loaded. – GillesC Jun 14 '14 at 10:07
  • Could you please post a full example of how can i use the jsapi to load the jqueryui tooltip? i have try many time but it seems that jqueryui don't work.. – ipel Jun 14 '14 at 11:20
  • 1
    From your example I see no reason to use the Google API. After just read the documentation provided in the answer below it shows how to use callback `google.load("visualization", "1", {"callback" : pageLoaded});` - but here you have 2 libraries and you must ensure jquery is loaded before jquery UI, meaning the callback of jquery would call jquery UI. But like I said, stick with ` – GillesC Jun 14 '14 at 11:24

1 Answers1

3

The idea is enhance the loading of your page. So your webpage rendering is not blocked whilst it downloads jquery and jqueryui. You will need to load your css too, I think you will need to do this inline, so you'll still need the link tag to load the jqueryui css.

Must admit I've not really used the google load api, but it appears to be doing a similar thing to requirejs i.e. dynamically loading client side scripts. It would be useful if you wanted to load different languages programatically. Perhaps if you had a scenario where maybe you don't need to load jqueryui in some conditions.

https://developers.google.com/loader/

Check out the above for a little more info.

Captain John
  • 1,859
  • 2
  • 16
  • 30