[wp-hackers] Adding A CSS Loader

Otto otto at ottodestruct.com
Mon Apr 23 21:27:59 GMT 2007


While that is an admirable goal, we're most likely talking about
static files here, no? Unless the CSS is dynamically generated, you're
just reading files, cat-ing them together, and shoving them to the
browser.

The benefit: You don't have multiple hits to the site for these files.
The cost: You do have a script call which is going to read all these
files from disk and serve it up to the browser as one combined thing.

The fact that you have even a single script call negates the benefit
of not having multiple server hits, IMO. Apache is really, really,
*really* good at serving static files. And modern versions of Apache
and browsers will combine all those requests into one single server
hit, by using a persistent connection. So no extra connection overhead
to worry about, really. Or not much anyway.

I just don't see that the caching would be particularly worth it
except for the case where the plugin is doing something like this:

<?php add_action('wp_head','my_styles');
function my_styles() { ?>
<style>
.plugin_style p {
blah: 0;
...
}
</style>
<?php } ?>

Which would put the plugins style directly into the webpage everytime.
Okay, so a lot of plugins do that. It's a bad idea, I grant you, but
that can be replaced with an external stylesheet and a wp_head call to
put the <link> code in place and you get browser caching of the CSS
file then.

The benefit of trying to cache CSS in the code just seems extremely
limited to me.



On 4/23/07, Jamie Holly <hovercrafter at earthlink.net> wrote:
>
> > 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?
> >
> >
>
> My original post was that we could use the new method to then add a caching
> mechanism to have WP combine all CSS files into one "master" CSS file that
> could be generated and stored/called from a server writeable directory (ie -
> cache or uploads). That way when you got a bunch of plugins working off this
> system, instead of having all those make additional server requests for
> their independent CSS file, a single CSS file would load. Of course we would
> have to look at options, such as enabling/disabling the caching and a cache
> delete function for plugin updates.
>
> Jamie Holly
> http://www.intoxination.net
>
> _______________________________________________
> 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