[wp-hackers] Adding A CSS Loader
Jamie Holly
hovercrafter at earthlink.net
Mon Apr 23 22:01:51 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.
What I am talking about is having Wordpress read in X number of static CSS
files and create a new static file with all the CSS in it (which is why I
was suggesting the uploads or cache directory to store it in, as it would
have the proper permissions). That would only happen every so often (if you
activate/deactivate a plugin or click a button in options to regenerate the
file if something goes wrong or gets changed). It would require no scripting
for the actual CSS load from the generated HTML, as it would still be a
static file - just a static file that WP created.
> 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.
>
>
>
That is a big problem I have seen with a lot of plugins. I have even seen
ones that go as far as to create a pretty permalink just to dump out what
should be a static CSS file. That seems like a lot of wasted work/resources.
Another benefit of the single CSS would be the .htaccess issue (people say
to put your rewrites in httpd.conf - not on option for the vast number of WP
sites on shared hosting). Since you get a lot of these CSS's buried 4 levels
deep in the directory (/wp-content/plugins/pluginname/), that means Apache
checks each directory level for any overrides in the .htaccess, for each CSS
file loaded.
Jamie Holly
http://www.intoxination.net
> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-
> bounces at lists.automattic.com] On Behalf Of Otto
> Sent: Monday, April 23, 2007 5:28 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Adding A CSS Loader
>
>
> 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
> >
> _______________________________________________
> 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