There and Back Again

HTML FAQ Answer: Other library integration plans

I answered an FAQ question tonight on the HTML_AJAX wiki, im posting the answer here as well since I know most people don’t check the wiki for changes every day.

Outside of this answer I’d like to hear from what other libraries people would like too see integrated with HTML_AJAX and the reasons for this.

Question:
Will HTML_AJAX integrate with other Javascript AJAX libraries such as scriptaculous? How would this integration look like?

HTML_AJAX doesn’t have specific plans to integrate with other JavaScript libraries. Part of this is because external dependencies make for a more complicated installation process. It might make sense to offer some optional dependencies on a library like scriptaculous automatically using its visual effects for the loading box or something, but there isn’t a lot to gain from making default visuals like that flashier since they are designed to be easily replaceable.

Most integration would take place in higher level components. Its unclear weather higher level components like that should be part of HTML_AJAX delivered through PEAR or if they should just be supported by HTML_AJAX and made available from http://htmlajax.org or some other site. If your interested in building widgets or components based on HTML_AJAX please let me know.

HTML_AJAX does however offer the ability to use its library loading mechanism with any JavaScript library. I use scriptaculous in conjunction with HTML_AJAX and I load both libraries through the server.

To do this you just need to register the library with your server and load add its flag to your include line.

PHP code

<?php

$this->server->registerJSLibrary('scriptaculous',
    array('prototype.js','scriptaculous.js','builder.js','effects.js','dragdrop.js','controls.js','slider.js'),'/pathto/scriptaculous/');

?>

HTML

4 thoughts on “HTML FAQ Answer: Other library integration plans

  1. Aaron Worms

    That is really nice!

    Adding a Javascript compressor, would be a nice touch. One of the things I don’t like about using javascript libraries is that to get what I need using libraries I don’t just use 1 library, but have to load up a couple different libraries, which causes too much overhead.

    If I could use take the JS libraries that I need and then load them up through HTML_AJAX, which would compress the js before serving it, that would rock.

    Another thing that I’ve wanted for a while is a way to create Javascript dependancies. For example I only need to use one effect out of a library, but instead of loading up the entire library I would use HTML_AJAX to call that effect. HTML_AJAX will then work out what functions are needed for that effect to work, compress the JS and serve it to me. That would rock ;)

  2. Ross

    Don’t forget that scriptaculous – has its own auto loading functions – so all you need to include is scriptaculous.js

    Also they have added url style get variables to specify what is included:

    i.e. including:

    Will load the base and the effects.js library..

    Javascript compression – can be tricky – best bet is to gzip the output from the webserver…

  3. Ross

    Dam filtered, the content!

    Include this as the source to load only the base and the effects lib.

    ‘js/scriptaculous.js?effects’

  4. Joshua Eichorn Post author

    Ross: The autoload in scriptaculous is slower since it makes multiple http requests instead of one. Also in a setup like this the scriptaculous auto load doesn’t work since it can’t figure out the correct path to use.

    You could easily set it up as a couple different keys if you wanted but I find myself using everything but builder.js on a regular basis (guess i could drop that from my include) because of larger widgets i’ve built so its just easier to pull it all in and let a single client side cache check be performed.