The 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:
script and css tags for your implementation. Even if YUI’s dependency tree changes in a future version, your code won’t have to.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>
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.
September 14, 2009 at 2:51 pm
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.
September 14, 2009 at 3:58 pm
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/
September 14, 2009 at 10:16 pm
Is there an equivalent library for java front-end?
September 15, 2009 at 6:04 am
Josh:
Is it as simple as
$loader->script();$loader->css();?
September 15, 2009 at 7:40 am
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
September 15, 2009 at 1:19 pm
Geoff,
Yep, it’s that simple.
September 16, 2009 at 1:58 pm
This rocks.
I’ve been waiting for this one.
Thanks for another great feature!
September 26, 2009 at 3:39 pm
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)
September 26, 2009 at 10:42 pm
@Eydun–
Absolutely — see http://www.yuiblog.com/blog/2009/09/14/yui-php-loader-beta-release/#comment-584585 from Geoff Green above.
-Eric
October 5, 2009 at 11:31 am
[...] 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, [...]
November 6, 2009 at 8:45 am
[...] 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 [...]