Thanks Mike and Otto. I will investigate this route further (though I am sure my user base will have something to say!).<br><br><div class="gmail_quote">On Thu, Dec 2, 2010 at 11:01 PM, <span dir="ltr"><<a href="mailto:michael@mfields.org">michael@mfields.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Sayontan,<br>
<br>
I agree with Otto here and I use method #1 in my plugins when I need to<br>
generate dynamic css. If the overhead of processing php on each request is<br>
an issue for you, might it be a good idea to store the dynamic css in an<br>
autoloaded option and print the value of the option to the head?<br>
<br>
-Mike<br>
<div><div></div><div class="h5"><br>
> Otto,<br>
> Method 1 is not better than Method 2 if a lot of your CSS is dynamic, as<br>
> is<br>
> the case with most themes that offer a lot of styling options. In such a<br>
> case using Method 1 you would be repeatedly running a lot of PHP calls to<br>
> dump the same CSS each time into your HTML. This is really inefficient<br>
> particularly in contrast to one extra HTTP request to get a pre-generated<br>
> file. Hence it is not something that can be shoved aside by saying "get<br>
> over<br>
> it" - Method 2 does improve caching performance significantly on several<br>
> occasions.<br>
><br>
> Sayontan.<br>
><br>
> On Thu, Dec 2, 2010 at 10:13 AM, Otto <<a href="mailto:otto@ottodestruct.com">otto@ottodestruct.com</a>> wrote:<br>
><br>
>> Ugh. Okay, this may be a bit long winded.<br>
>><br>
>> For the cases where you're creating dynamic CSS, then there is one<br>
>> correct way to do it, and several incorrect ways to do it. Let's go<br>
>> over the possibilities.<br>
>><br>
>> Method 1: Insert the dynamic CSS directly into the HTML using the<br>
>> wp_head<br>
>> call.<br>
>><br>
>> Method 2: Write dynamic CSS to a file, link to the file in the head.<br>
>><br>
>> Method 3: Hook into the template-loader or init to create CSS output<br>
>> based<br>
>> on<br>
>> a special GET variable you define.<br>
>><br>
>> Method 4: Style.php, which is linked to from the head, and outputs<br>
>> dynamic css. Usually this has to include wp-load.<br>
>><br>
>><br>
>> I listed those in that order because they go from "best" to "worst".<br>
>> I'll explain why now. :)<br>
>><br>
>> Method 1 has the lowest server impact. When you make the call to get<br>
>> the page, it creates the page and outputs all the dynamic stuff in one<br>
>> shot. Some people find the CSS in the html to be aesthetically<br>
>> displeasing, but the fact of the matter is that this is the fastest,<br>
>> simplest, and best way to do it.<br>
>><br>
>> Method 2 has a problem in that you're doing file writing from the<br>
>> theme. This is bad because you cannot guarantee that you have<br>
>> permissions to even write files. Assuming you try to write them to the<br>
>> uploads folder, then part of your theme is now outside the theme<br>
>> directory, which is confusing. Also, by including the CSS as a<br>
>> separate file, you're creating another call to the server, which even<br>
>> Google Webmaster Tools will tell you is a thing to avoid.<br>
>><br>
>> Method 3 is the same as method 2, except now instead of writing the<br>
>> file, you make a call to <a href="http://example.com/?css=whatever" target="_blank">http://example.com/?css=whatever</a> and then<br>
>> your code intercepts that and produces the CSS on-the-fly, via<br>
>> whatever means, then exits. This avoids the file writing problem, but<br>
>> now it's not<br>
>> only making an extra server call, but it's also loading all of<br>
>> WordPress up again, which creates a higher server CPU impact.<br>
>><br>
>> Method 4 is the same as method 3, basically, except that you're<br>
>> referencing some PHP file directly, which now has to a) find wp-load,<br>
>> b) load WordPress, and c) produce the resulting CSS output. Worst of<br>
>> all cases: two calls to the server, WordPress loads twice, and you're<br>
>> now having to search around to figure out how to load WordPress again<br>
>> just so you can access the database.<br>
>><br>
>><br>
>> So the end statement here is to always use method 1. Okay, so you find<br>
>> CSS in the HTML header code to be unpleasant. My advice: get over it.<br>
>> Every other way of doing things not only requires an extra HTTP<br>
>> request to the server, but most of them also require a whole lot of<br>
>> extra PHP processing. Think about it this way: You've already got<br>
>> WordPress loaded up to generate the page. The most sensible thing to<br>
>> do is to go ahead and generate the dynamic part of the CSS right now<br>
>> as well. Just make that dynamic part as small as possible. Minify it<br>
>> into one-line if you want.<br>
>><br>
>> Note that WordPress itself uses method 1 for the custom background<br>
>> image and custom header image stuff. It does it this way because it's<br>
>> the best way to do it.<br>
>><br>
>> -Otto<br>
>><br>
>><br>
>><br>
>> On Thu, Dec 2, 2010 at 11:57 AM, Simon Prosser <<a href="mailto:pross@pross.org.uk">pross@pross.org.uk</a>><br>
>> wrote:<br>
>> > There is a more sensible way to do this. Use a style.php file that<br>
>> > prints your custom css<br>
>> > with text/css header and a far future expires, then the browser will<br>
>> > cache it locally.<br>
>> ><br>
>> > My theme [JustCSS] uses this to cache the css.<br>
>> > <a href="https://github.com/Pross/JustCSS" target="_blank">https://github.com/Pross/JustCSS</a><br>
>> ><br>
>> > On 2 December 2010 17:46, Sayontan Sinha <<a href="mailto:sayontan@gmail.com">sayontan@gmail.com</a>> wrote:<br>
>> >> What about instances of caching? E.g. I have a lot of look and feel<br>
>> options<br>
>> >> that can be set by the user. However if you attempt to print them out<br>
>> as<br>
>> >> dynamic CSS on the fly it creates extra server load, not to mention<br>
>> an<br>
>> ugly<br>
>> >> lot of CSS before the content in the page's source. Instead the CSS<br>
>> is<br>
>> saved<br>
>> >> as a local file at the time of saving the options and then that file<br>
>> is<br>
>> >> linked in the source.<br>
>> >><br>
>> >> On Thu, Dec 2, 2010 at 8:50 AM, Otto <<a href="mailto:otto@ottodestruct.com">otto@ottodestruct.com</a>> wrote:<br>
>> >>><br>
>> >>> On Thu, Dec 2, 2010 at 3:02 AM, Sayontan Sinha <<a href="mailto:sayontan@gmail.com">sayontan@gmail.com</a>><br>
>> wrote:<br>
>> >>> > I am curious as to what qualifies as a better way of doing things.<br>
>> E.g.<br>
>> >>> > I<br>
>> >>> > have code where depending on selections certain stylesheets are<br>
>> grouped<br>
>> >>> > together, then either they are compressed and/or minified.<br>
>> >>><br>
>> >>> See, that sounds awfully functional to me. Why would you want the<br>
>> >>> theme to be doing that?<br>
>> >>><br>
>> >>> A theme is supposed to describe how the site looks, not how the site<br>
>> >>> works. Sure, for custom jobs, we all do it and put this sort of<br>
>> thing<br>
>> >>> in the theme, but remember that the directory is supposed to hold<br>
>> >>> themes to be used for public consumption. Anybody can use them.<br>
>> >>><br>
>> >>> So doesn't it make a bit more sense to make this sort of<br>
>> >>> compression/minification more generic, able to apply to any theme,<br>
>> and<br>
>> >>> then to put it in a plugin?<br>
>> >>><br>
>> >>> Also, look into wp_enqueue_style, which is capable of minification<br>
>> and<br>
>> >>> combining css files.<br>
>> >>><br>
>> >>> -Otto<br>
>> >>> _______________________________________________<br>
>> >>> theme-reviewers mailing list<br>
>> >>> <a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
>> >>> <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
>> >><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> Sayontan Sinha<br>
>> >> <a href="http://mynethome.net" target="_blank">http://mynethome.net</a> | <a href="http://mynethome.net/blog" target="_blank">http://mynethome.net/blog</a><br>
>> >> --<br>
>> >> Beating Australia in Cricket is like killing a celebrity. The death<br>
>> gets<br>
>> >> more coverage than the crime.<br>
>> >><br>
>> >><br>
>> >> _______________________________________________<br>
>> >> theme-reviewers mailing list<br>
>> >> <a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
>> >> <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
>> >><br>
>> >><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> > My Blog: <a href="http://www.pross.org.uk/" target="_blank">http://www.pross.org.uk/</a><br>
>> > Plugins : <a href="http://www.pross.org.uk/plugins/" target="_blank">http://www.pross.org.uk/plugins/</a><br>
>> > Themes: <a href="http://wordpress.org/extend/themes/profile/pross" target="_blank">http://wordpress.org/extend/themes/profile/pross</a><br>
>> > _______________________________________________<br>
>> > theme-reviewers mailing list<br>
>> > <a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
>> > <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
>> ><br>
>> _______________________________________________<br>
>> theme-reviewers mailing list<br>
>> <a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
>> <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> Sayontan Sinha<br>
> <a href="http://mynethome.net" target="_blank">http://mynethome.net</a> | <a href="http://mynethome.net/blog" target="_blank">http://mynethome.net/blog</a><br>
> --<br>
> Beating Australia in Cricket is like killing a celebrity. The death gets<br>
> more coverage than the crime.<br>
> _______________________________________________<br>
> theme-reviewers mailing list<br>
> <a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
> <a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
><br>
<br>
<br>
_______________________________________________<br>
theme-reviewers mailing list<br>
<a href="mailto:theme-reviewers@lists.wordpress.org">theme-reviewers@lists.wordpress.org</a><br>
<a href="http://lists.wordpress.org/mailman/listinfo/theme-reviewers" target="_blank">http://lists.wordpress.org/mailman/listinfo/theme-reviewers</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Sayontan Sinha<br><a href="http://mynethome.net" target="_blank">http://mynethome.net</a> | <a href="http://mynethome.net/blog" target="_blank">http://mynethome.net/blog</a><br>
--<br>Beating Australia in Cricket is like killing a celebrity. The death gets more coverage than the crime.<br><br>