1

I think I have a design issue which makes my site very slow! Probably I used the EE templating in the wrong way, however I can't find a better way, hopefully until now!

From php I'm used to include files in a if else structure so I will include the correct file if specific conditions are met. For the templates I do the same, but loading time's are up to 5 seconds for just loading a couple of channel entries (6). That can't be right!

So at the moment I have the following which is very slow:

Template group called "site". This index.html file is the index file of the page. All other template are loaded inside this template.

{embed="include/head"}
  <body>
    {embed="include/header"}
    // some HTML

    {if segment_1 == ''}
      {embed="include/home"}
    {if:elseif segment_1 == 'smartphone' OR segment_1 == 'tablet'}
       {embed="include/merk"}
    {if:else}
      {embed="include/404"}    
    {/if}

    {embed="include/foot"}
  </body>
</html>

For the home page, where include/home is included, it loads just normal, within 1 second.

But when URL segment_1 is for example 'smartphone', it gets very slow. So below the template include/merk

<section class="row" id="content">
  <div class="col-xs-11 midden">
  {if segment_2 == ""}
    {!-- De smartphone of tablet pagina met merken overzicht. --}
    <ul>
      {exp:channel:entries channel="merken" orderby="title" sort="asc" category="{segment_1_category_id}" dynamic="no" disable="member_data|pagination"}
      <li><a href="{segment_1}/{exp:stringy:lowercase}{title}{/exp:stringy:lowercase}"><img src="{merk_afbeelding}" width="180" height="133"></a></li>
      {/exp:channel:entries}
    </ul>
  {if:elseif segment_2 != "" AND segment_3 == ""}
      <ul class="dropdown-menu drop-model">
        {exp:channel:entries channel="modellen" orderby="volgorde" sort="asc" category="{segment_1_category_id}" limit="999" dynamic="no" disable="member_data|pagination"}
          {if "{segment_2}" ==  "{exp:stringy:lowercase}{merken:title}{/exp:stringy:lowercase}"}
          <li><a href="{exp:stringy:lowercase}/{segment_1}/{segment_2}/{url_title}{/exp:stringy:lowercase}">{title}</a></li>
          {/if}
        {/exp:channel:entries}
      </ul>
    <ul class="list-unstyled grid-type modellen">
      {exp:channel:entries channel="modellen" orderby="volgorde" sort="asc" category="{segment_1_category_id}" limit="999" dynamic="no" disable="member_data|pagination"}
        {if "{exp:stringy:lowercase}{segment_2}{/exp:stringy:lowercase}" ==  "{exp:stringy:lowercase}{merken:title}{/exp:stringy:lowercase}"}
        <li><h2>{title}</h2><a href="{exp:stringy:lowercase}/{segment_1}/{segment_2}/{url_title}{/exp:stringy:lowercase}" title="{title}"><img src="{model_afbeelding}" alt="{title}" width="100" height="130"></a></li>
        {/if}
      {/exp:channel:entries}
    </ul>

  {if:elseif segment_3 != "" AND segment_4 == ""}
    {exp:channel:entries channel="modellen" url_title="{segment_3}" dynamic="no" disable="member_data|pagination"}
    {reparaties}
    <ul class="list-unstyled grid-reparatie">
       {items}  
       <li class="list-reparatie">
        <article>
          <h2 class="reparatie">{title}</h2>
        </article>
      </li>
      {/items}
    </ul>
    {/reparaties}
    {/exp:channel:entries}
  {/if}
  </div>
</section>

There's an if else structure that determines what to show. The first if, segment_2 == "" will load some channel entries. There are about 6 entries that will match. However loading time takes up to 5 seconds!

Now I created a group called smartphone and put a part of the first if condition in the index.html file (only the 6 channel entries loaded). Now the page loads in less than 1 second. The URL would be http://www.mywebsite.nl/smartphone

After smartphone, there will be a brand, for example apple and the URL would be http://www.mywebsite.nl/smartphone/apple.

The brand however is loaded from a channel entries with a url-title 'apple'. So if I now use the mentioned URL, it will load the index.html file in the template group 'smartphone' because the template apple.html doesn't exist. But this index file does not load the models of apple, but is loads the brands... So I would need to use a if else structure again what makes it really slow...

It looks like it is loading everything in the other if else conditions to, which makes it so slow. But I suppose that if EE conditions in a if statement doesn't match, it will not do anything with that code!

So.. what am I doing wrong...

3
  • 2
    When you use if else statements EE executes all the code in every statement before deciding what to output. This makes it very slow indeed. What you need is devot-ee.com/add-ons/switchee Dec 23, 2013 at 10:45
  • @JelleDijkstra Great! I will have a look at that!
    – Timo002
    Dec 23, 2013 at 11:16
  • I used the addon that @JelleDijkstra mentioned (switchee). Works like charm! Loadtimes have been improved from 4s to less than 1s. JelleDijkstra, I think you should place a answer instead of a comment! Credits to you! Thanks!
    – Timo002
    Dec 23, 2013 at 12:57

2 Answers 2

4

When you use if else statements EE executes all the code in every statement before deciding what to output. This makes it very slow indeed. What you need is devot-ee.com/add-ons/switchee

Now gimme some credits ;-)

2

As has been mentioned in a comment, EE will process each embed within the if:else structure before deciding what to do so it will slow your site down considerably.

But, looking at what you're doing, why not use EE's template/entry url structure to achieve what you're doing?

Create a template group for Smartphone. Then create your index template within that group, loading the embed you need (or use the code directly on the templates if possible).

You may then be able to use EE's native url parsing to do the rest of the work being done by "merk". But even if not then I think you could possibly rationalise the content of that template (especially the conditional logic) down to make it a bit quicker.

1
  • I tried to use a template group "smartphone", but than I should do the same in the index.html file of that template group as JelleDijkstra mentioned in his comment. So I used the switchee addon which took me less than an hour to implement!
    – Timo002
    Dec 23, 2013 at 12:59

Your Answer

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

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