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 website. 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="http://{segment_1}/{exp:stringy:lowercase}{title}{/exp:stringy:lowercase}">{merk_afbeelding}</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="http://{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><p><a href="http://{exp:stringy:lowercase}/{segment_1}/{segment_2}/{url_title}{/exp:stringy:lowercase}" title="{title}">{model_afbeelding}</a></li><br />
{/if}<br />
{/exp:channel:entries}<br />
</ul><br />
<br />
{if:elseif segment_3 != "" AND segment_4 == ""}<br />
{exp:channel:entries channel="modellen" url_title="{segment_3}" dynamic="no" disable="member_data|pagination"}<br />
{reparaties}<br />
<ul class="list-unstyled grid-reparatie"><br />
{items} <br />
<li class="list-reparatie"><br />
<article><br />
<h2 class="reparatie">{title}</h2><br />
</article><br />
</li><br />
{/items}<br />
</ul><br />
{/reparaties}<br />
{/exp:channel:entries}<br />
{/if}<br />
</div><br />
</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…