Save 37% off PRO during our Black Friday Sale! »

EE, Faster

EE, Faster

Presented at the 2011 ExpressionEngine and CodeIgniter Conference in Brooklyn, New York. This talk is an overview on the common causes of slow load times in ExpressionEngine sits and how you can overcome them. The goal of this talk was to get listeners on the right track in diagnosing their site issues and researching further on their own.


Jacob Russell

October 24, 2011


  1. EE, FASTER Jacob Russell - devot:ee

  2. Three Parts • Three parts to making sites fly: •

    Server choice and setup • Code and db optimization (HTML / CSS / JS / PHP) • ExpressionEngine Optimization
  3. ExpressionEngine Optimization • Good Coding Practices • Caching Techniques •

  4. Tools Template Debugging Output Profiler

  5. Problem Areas

  6. Conditionals • Simple vs Complex Conditionals • Simple Conditionals execute

    logic BEFORE contents • Complex Conditionals execute logic AFTER contents
  7. Is it Simple? • NO Else • NO And, Or,

    etc. • NO Late Parsing Variables • NO Nested complex if statements
  8. Consider • Pages with large amounts of logic split by

    a complex if will run ALL the logic • Can lead to a lot of excess overhead • Templates that handle both listing and single entry are a common cause
  9. Exception • Embeds run AFTER complex conditionals • If a

    complex conditional must be used, embed may speed it up • Still has downsides of an embed
  10. Alternatives • PHP If • With PHP on input, if

    statements can be used properly • Must have PHP turned on, ‘on output’ no longer available • Add-ons
  11. Add-ons • Switchee • Brings PHP’s switch case logic into

    EE • Parse=”inward” avoids unwanted code • Not optimal for all logic situations • IfElse • Early parsing with If statements • Both from Mark Croxton
  12. Loops • Loops are powerful, but also dangerous • Channel

    Entries, Channel Categories, Matrix Output • Remember that the code repeats for each result
  13. Nested Loops • Channel Entries inside Channel Categories • What

    if there’s an embed inside that? • Overhead increases exponentially.
  14. Results {exp:channel:categories category_group="1"}{!-- Venues --} {exp:channel:entries channel="events" category="{category_id}"} <h1>{title}</h1> <ul>

    <li><h2>Attendees</h2></li> {reverse_related_entries channel="people"} <li>{title}</li> {/reverse_related_entries} </ul> {/exp:channel:entries} {/exp:channel:categories} 10 Venues, 20 Events and 40 People = 8,000 Iterations 20 Venues, 160 Events and 1100 People = 3,520,000 Iterations
  15. Embeds • Great for organization and not repeating code •

    Bad for speed • Really, really bad for speed
  16. How they Parse • Second to last in parse order

    • Followed only by global vars and a small list of other vars • Each embed runs like a new page, restarting the template engine
  17. How it Looks Index Handler Listing Single Entry Header Footer

    Sidebar Item Sidebar Item Sidebar Item Comments Page Top
  18. Result • Loading a single entry page runs the template

    engine 10 times • Loading a listing page runs it 6 times • To get to an entry page from a listing is like loading 16 separate pages.
  19. Alternatives • Fewer Embeds • Repeating code means tougher maintenance,

    faster performance • Combine Embeds • PHP Requires • PHP must be on input • Other Options!
  20. GLOBAL VARIABLES • User defined static content • Late Parsing

    (Can’t feed channel:entries) • Not very flexible
  21. Other Variables • Fresh Variables • Low Variables • Powerful

    • Many Fieldtypes have been ported to Low Variables
  22. SNIPPETS • New with EE2 • Part of the template

    they’re included in, not separate like an embed • Low Overhead! • Early Parsing
  23. Caching • Template, Tag, and Query Caching • Stores a

    cached copy for each URI in a file • Limits db traffic in favor of a file-system lookup
  24. Template vs Tag • Template usually the better choice •

    Larger scope means fewer separate caches • Tag caching makes sense when you can only cache a small part of a page • Helps avoid logged in/logged out conditionals
  25. Template Caching • Renders a whole page, stores it as

    a flat file for specified time • Limit of 1000 files • When limit reached, cache clears and starts over
  26. Tag Caching • Stores each tag cache in a file,

    based off URI • Multiple file lookups per template • Unknown limit
  27. Query Caching • Caches queries per URI • Limit of

    150, then cleared • Other options available in MySQL
  28. Consider • Site Structure • More URI’s means more cache

    files, hit limit faster • Fewer URI’s mean longer cache times • Faster? • Simple Pages may be faster without caching • EngineHosting tuned for fast db lookups
  29. Template Morsels • Caching Alternative • Replace embeds and complex

    global variables
  30. Caching Options • Cache Refresh • On Template Change •

    On Channel Update • Time Expire
  31. Thanks! @jacobrussell EE Podcast - Thursday, October 27 Watch

    twitter for a possible expanded guide in the future (no promises!)