8

Follow-up To Loading CSS And JS Conditionally


Posted by Artem Russakovskii on January 15th, 2010 in Programming, Wordpress
Share

8 Responses to “Follow-up To Loading CSS And JS Conditionally”

    5 Comments:
  1. Otto says:

    *Always* avoid output buffering if you possibly can. It has a massive negative effect on page load times in most cases, and it's a memory and CPU hog to boot.

    And yes, there are cases where it makes sense to not include your script code on every page. Like if you have a dedicated gallery system or something. Sure, that makes perfect sense.

    But I think that *most* plugins will probably have some kind of impact on every page. You have to weigh the costs vs. the benefits. If you're only going to not load the code on 1 out of 10 pages, then it makes no sense to add expensive PHP loops to determine that.

    Figure out your use cases first, don't just assume that this will always be faster, because it won't.

    • By all means – I never said it should be done all the time.

      I think ideally, the plugin author would provide an option to do so, clearly explaining the trade-offs.

      I use the wp-poll feature one time here, and yet it loads on every page – it could be better to optimize it.

      However, if you run polls on the sidebar or on every other posts, you wouldn't benefit from this.

      Again, I'd like to repeat: I don't think it should be white and black – there are clearly design decisions that need to be made by the authors and it's up to them to provide us with additional options, but if they don't know how to do it, they'll never even know to think of them, which is why discussions like this one here are invaluable.

      Thanks for the feedback about output buffering. Do you have any benchmarks to back up the "massive" part?

  2. joecr says:

    I avoid output buffering like the plague because I'm on shared hosting & I know if I do that I will go over my CPU & memory limits very quickly. I only played with it on my computer.

      • joecr says:

        This in the results from a very small test that I ran, just as an idea of how much of an issue this is. I displays a form & then parses the results. The time didn't really change much for the form but the memory did go up for buffering in all tests as I expected.

        I remember in the books I've read that they suggest avoiding buffering like the plague, & to dump the buffer soon & often if you must resort to using a buffer at all.

        Display form

        no buffer

        Memory usage in bytes 127416
        Script executed in 0.0001 seconds.

        with buffer

        Memory usage in bytes 127840
        Script executed in 0.0001 seconds.

        display results

        no buffer

        Memory usage in bytes 129120
        Script executed in 0.0067 seconds.

        with buffer

        Memory usage in bytes 129528
        Script executed in 0.0766 seconds.

  3. 3 Pings:
  4. [...] I have posted a follow-up in response to some comments received around the [...]

  5. [...] This post was prompted by this question from [...]

  6. [...] This post was mentioned on Twitter by ArtemR, ArtemR. ArtemR said: Just posted Follow-up To Loading CSS And JS Conditionally: http://ping.fm/VVLbw [...]

Leave a Reply

Connect with Facebook