Using other libraries

If you are more comfortable using other libraries, you can also load and use them in a similar way to jQuery.

The following is how we load jQuery:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.2.min.js"></script>')
</script>

Let us say, you want to use another library (like MooTools), then look up the Google Libraries API to see if that library is available at developers.google.com/speed/libraries/. If it is available, just replace the reference with the appropriate reference from the site. For example, if we want to replace our jQuery link with a link to MooTools, we would simply replace the following code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>

With the following line of code:

<script src="ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js">
</script>

We will also download Mootools' minified file to the js/vendor folder locally and replace the following code:

<script>window.jQuery||document.write('<script src="js/vendor/jquery-1.7.2.min.js"></script>')
</script>

With the following line of code:

<script>window.jQuery||document.write('<script src="js/vendor/mootools-core-1.4.5-full-compat-yc.js"></script>')
</script>

For more information on why we use local copies of the code, please check Chapter 2, Starting Your Project. But we are pretty happy with our default choice of jQuery, so let us proceed with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset