[wp-hackers] Adding A CSS Loader

Otto otto at ottodestruct.com
Mon Apr 23 16:28:53 GMT 2007


In default-filters.php, there's this:

add_action('wp_head', 'wp_print_scripts');

Which does just what you're thinking, printing out the scripts and
their dependencies and such. Plugins can indeed use
wp_enqueue_script() to make it load in the head. The widgets plugin
did that (before it became integrated into the core, of course).

I'm not sure there's a real need for a CSS specific loading function.
The entire function is basically just going to be something like this:

`function add_css($cssfile) {
add_action('wp_head', create_function('$a', 'echo "<link
rel=\"stylesheet\" href=\"'.$cssfile.'\" type=\"text/css\" />";');
}`

Because all it will do will add the line to the head. Nothing
particularly special. Sure, it's a shortened form and a convenience to
plugin/theme devs, but is it really necessary?


On 4/23/07, Robin Adrianse <robin.adr at gmail.com> wrote:
> I believe we already do this with the script loader. wp_register_script() to
> register a script, and wp_enqueue_script() to queue it up. But it may or may
> not hook into wp_head. I'd have to look into that.
>
> On 4/23/07, Jamie Holly <hovercrafter at earthlink.net> wrote:
> >
> > >
> > > This seems like a good proposal.
> > >
> > > I would like to add the same idea for the addition of javascript.
> > > Although I wonder about the order which might cause issues with
> > > javascript files (such as with prototype and jquery). I'm not sure if
> > > the same would apply to css.
> > >
> > > grtz
> > > BjornW
> > >
> >
> > This would also be a good idea. We could add a load order to the function
> > -
> > add_js('js file name',load_order), with the higher numbers loading before
> > the lower numbers.
> >
> > I think this would all be best in a major version release (ie: 3.0), but
> > overall it would reduce the calls to the server to load files. If you got
> > 5
> > plugins loading CSS and JS, that is an additional 10 calls to the server.
> > Add that to other items, such as theme images, and a page quickly becomes
> > inflated with requests.
> >
> > Jamie Holly
> > http://www.intoxination.net
> >
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list