YUI PHP Loader Beta Release
September 14, 2009 at 2:19 pm by Eric Miraglia | In Development | 11 CommentsThe YUI PHP Loader is a server-side utility for loading YUI JavaScript and CSS; version 1.0.0 beta 1 is available for download from YUILibrary.com today.
PHP Loader, originally written by longtime YUI engineer Adam Moore and now developed and maintained by fellow Yahoo Chad Auld, has several key features that make it easier to use YUI in PHP-based applications:
- Reliable, sorted loading of dependencies: You specify the version of YUI that you’re using, the modules you want to use, and PHP Loader outputs the requisite
scriptandcsstags for your implementation. Even if YUI’s dependency tree changes in a future version, your code won’t have to. - Support for performance best-practices: PHP Loader has three strategies to help you reduce HTTP requests — support for the Yahoo! CDN and its combo-handler (which aggregates YUI files into single HTTP requests on the fly), support for YUI’s rollup files, and (in the event you don’t want to serve YUI from Yahoo!’s servers) a lightweight combo-handler of its own. Server-side performance is fast as well, leveraging PHP’s APC cache.
- Extensible metadata format: YUI PHP Loader ships with YUI library metadata (for both YUI 2 and YUI 3); however, the application is generic and can be extended to support your own custom JavaScript and CSS modules — whether or not they use YUI at all.
PHP Loader is simple to use:
include("loader.php");
$loader = new YAHOO_util_Loader("2.7.0");
//Configure your instance; for example, you can turn off rollups
$loader->allowRollups = false;
//Specify YUI components to load
$loader->load("yahoo", "dom", "event", "tabview", "grids", "fonts", "reset");
//Output the tags (this call would most likely be placed in the document head)
$loader->tags();
The above PHP script would output the following to the page:
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/fonts/fonts-min.css" /> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/grids/grids-min.css" /> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset/reset-min.css" /> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/tabview/assets/skins/sam/tabview.css" /> <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/yahoo/yahoo-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/dom/dom-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/event/event-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/element/element-min.js"></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.7.0/build/tabview/tabview-min.js"></script> */
Leveraging the combo-handler on Yahoo!’s servers, you can flip the combine setting on…
$loader->combine = true;
…and end up with just a single HTTP request for CSS and one more for JavaScript:
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.7.0/build/reset-fonts-grids/reset-fonts-grids.css&2.7.0/build/tabview/assets/skins/sam/tabview.css"> <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js&2.7.0/build/element/element-min.js&2.7.0/build/tabview/tabview-min.js"></script>
YUI PHP Loader links:
- Read the documentation
- Download the latest release, including functional examples, from YUILibrary.com
- File bug reports or feature requests on YUILibrary.com
- YUI PHP Loader is hosted on GitHub, where you grab the latest source
Welcoming a New YUI Contributor: Chad Auld
Chad Auld has driven the release of PHP Loader, and big thanks are owed to him for taking ownership of this application and adding a series of fantastic features as he prepped it for this beta release. You may know Chad from his work on MiaCMS and the Sideline AIR application for Twitter search. We’ve been looking for an opportunity to collaborate with him for awhile, and we couldn’t be happier to have that happening on this project.
Share and extend: Bookmark with del.icio.us | digg it! | reddit!
11 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment

Copyright © 2006-2010 Yahoo! Inc. All rights reserved. Privacy Policy - Terms of Service
Powered by WordPress on Yahoo! Web Hosting.


No way. I’m minutes away from starting a project that this PHP Loader is absolutely perfect for.
You should make a note somewhere that the script() and css() methods allow you to output the tag sets/combos in separate areas of your markup – I was thinking that I couldn’t use this at first until I actually downloaded it and looked at the source.
Comment by Josh L — September 14, 2009 #
Nice post. I’ll need to take a closer look.
Btw, another PHP bundler for JavaScript and CSS files is here: http://www.subchild.com/2008/08/07/simple-javascript-and-css-file-bundler/
Comment by Aleksandar Kolundzija — September 14, 2009 #
Is there an equivalent library for java front-end?
Comment by Phaniraju — September 14, 2009 #
Josh:
Is it as simple as
$loader->script();$loader->css();?
Comment by Geoff Green — September 15, 2009 #
Phaniraju,
Not yet. We’d love for someone to fork the project on GitHub and build a Java version (http://github.com/yui/phploader ) — and ASP, etc.
-Eric
Comment by Eric Miraglia — September 15, 2009 #
Geoff,
Yep, it’s that simple.
Comment by Josh L — September 15, 2009 #
This rocks.
I’ve been waiting for this one.
Thanks for another great feature!
Comment by David M Patterson — September 16, 2009 #
Sounds interesting. Have not though tried the PHP Loader yet.
Does it provide the option to output ccs-files before and js-files before ? (for best performance)
Comment by Eydun — September 26, 2009 #
@Eydun–
Absolutely — see http://www.yuiblog.com/blog/2009/09/14/yui-php-loader-beta-release/#comment-584585 from Geoff Green above.
-Eric
Comment by Eric Miraglia — September 26, 2009 #
[...] been a busy month here with YUI 2.8.0, YUI PHP Loader 1.0.0 beta 1, and YUI 3.0.0 all hitting the wires — and with our first public YUI developer conference, [...]
Pingback by In the Wild for October 5, 2009 » Yahoo! User Interface Blog (YUIBlog) — October 5, 2009 #
[...] Auld (@chadauld) is a Yahoo! engineer best known for his work on MiaCMS and Sideline. Chad recently drove the open-source release of YUI’s PHP Loader (taking over from original developer Adam Moore [@admo]), and he came to [...]
Pingback by YUI Theater — Chad Auld: “Introducing PHP Loader” » Yahoo! User Interface Blog (YUIBlog) — November 6, 2009 #