I have a page template that runs exceptionally slow (average 20 seconds to load). These pages are event pages and require certain information to be shown pre-event vs. post event. There are also competitors and judges, along with their lightboxed profiles. There are sponsors, comments, and additional information section. Because of this, within my code I know that there are a ton of conditionals. This is also an image heavy site.

What is a standard number of conditionals that won't overload my page? How can I get around using so many? How do you successfully code an ExpressionEngine page with this much content? Looking for any advice - I've been unsuccessful in trying to speed up this page for a very long time now.

I'm on ExpressionEngine v2.5.2, and here is my template code: http://codeviewer.org/view/code:3ca2. I am using plugins like Pixel&Tonic's Matrix and ED ImageResizer.

  • The answer below tells you what you need to do. Basically because you're using advanced conditionals, the entire template gets parsed, even though only parts of it get shown. Dropping in one of the parse-order reversing plugins below will stop the excess code from executing. Commented Feb 21, 2014 at 1:46
  • If you have Matrix fields with alot of rows, make sure your webhost doesn't have open_base_dir restrictions on. That will kill performance, especially with the matrix field.
    – aelvan
    Commented Feb 21, 2014 at 8:38
  • Thanks (particularly for not judging my intense code!) - looking into the plugins below now. @aelvan - is open_base_dir a server-wide, site-wide, or individual page setting? Commented Feb 21, 2014 at 16:32
  • It's a PHP setting, so depending on your server, it's server- or site-wide. Have a look in Tools > Utilities > PHP Info, and search for open_basedir. If it has a value, restrictions are in effect.
    – aelvan
    Commented Feb 22, 2014 at 17:50
  • But, looking at you code, I'd say that you should probably try to refactor and simplify it anyways. That's ALOT of if's. ;) And it really kills performance in the template parser.
    – aelvan
    Commented Feb 22, 2014 at 17:53

2 Answers 2


If else statements are killing! They slowdown your site because all code is executed, also the code that doesn't match the if condition.

Use switchee for if else statements and your page will load much faster! Link: http://devot-ee.com/add-ons/switchee. You will be amazed!

Description of the plugin:

With EEs if/else advanced conditionals, each condition is parsed before being removed at the end of the template parsing process. This means if you wrap if/else tags around lots of other tags then your template will be running many unnecessary queries and functions.

Using Switchee instead you can ensure that unmatched conditions are removed from the template before they can be parsed. This can make your template significantly more efficient and your pages will render more quickly.

  • 1
    Note there is also the ifelse plugin, which works exactly the same but for if else statements instead of a switch. Commented Feb 21, 2014 at 1:45
  • I've had a lot of trouble understanding how to use switchee in the past - any guidance would be appreciated. However, I did add the ifelse plugin and it didn't seem to help. am i doing this right? I installed the plugin and wrapped all of my outer-most advanced conditionals in the ifelse string -- codeviewer.org/view/code:3ca7 Commented Feb 21, 2014 at 19:06
  • At the moment I don't have the time to help you out with the switchee code. But it's really worth trying! I had a couple of ifelse statements after each other and the page took almost 5 seconds to load. After switching to switchee (nice wordplay) the page loaded in 700ms!
    – Timo002
    Commented Feb 21, 2014 at 20:00

I hope I can offer a few more suggestions to help.

  1. Try using the disable tag in your exp:channel:entries line to reduce some unnecessary queries.

  2. Use {if}{/if} and {if}{/if} instead of {if}{if:else}{/if} whenever possible. EE support people have recommended that to me a number of times.

  3. Turn on Display Output Profiler and Display Template Debugging. Note the large number of database queires, in part because of plugins and conditionals, and identify the biggest problem areas. It's a matter of opinion, but I try to keep my total queries per page to no more than 30-40.

  4. Instead of Img Resizer, try using the native Image Manipulations to reduce the number of database queries. I find it helps to use plugins only when absolutely necessary.

  5. You have two embeds at the top for header and navigation. Can they be combined?

  6. Note that Disqus uses a lot of javascripts, slowing the page even more.

  7. Turn on template caching.

  8. Use gtmetrix.com to analyze choke points even further.


  • Scott - lots of great tips here! In particular, I haven't tried 1-4. Hopefully those will help. Will let you know how it goes. Commented Feb 26, 2014 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.