ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Guidance on optimising complex template with conditional url segments

August 31, 2012 7:30am

Subscribe [3]
  • #1 / Aug 31, 2012 7:30am

    Jonathan Schofield

    175 posts

    Post edit: you may want to skip to the follow-up post where I think I’ve expressed what I’m trying to ask more concisely.

    I have a lot going on in a single template with a lot of fields being queried and a couple of relationships. Initially I had the template just generating urls of the form:

    /schools
    /schools/{url_title}

    But because the single entry part of it has several page segments that require a lot of processing and that’s leading to slow page loading, I’m now thinking it would be better to split this up further to generate:

    /schools
    /schools/{url_title}
    /schools/{url_title}/courses
    /schools/{url_title}/accommodation-travel

    …and have those latter 2 url types be injected on demand into the main single entry URL at /schools/{url_title}.

    I’d be grateful if you could confirm that the logic of the following abstracted template makes good use of the way EE parses things with regard to segment conditionals. Or whether you can see an obvious tweak that would optimise things better…

    <head>
      {if segment_2 == ""}
        <title>Schools SEO Title</title>
      {/if}
    
      {if segment_2 != "" AND segment_3 == ""}
        <title>{title}, {location}</title>
      {/if}
      
      {if segment_3 == "courses"}
        <title>Courses at {title}, {location}</title>
      {/if}
    
      {if segment_3 == "accommodation-travel"}
        <title>Accommodation and Travel for {title}, {location}</title>
      {/if}
    </head>
    
    <body>
      Global header <!-- includes snippets and an embed -->
      
    <!-- multiple entries section page -->
      {if segment_2 == ""} <!-- /schools -->
        Intro
        Synopses of all schools
      {/if}
    <!-- /multiple -->
    
    <!-- single entry pages -->
      {if segment_2 != ""} <!-- /schools/{url_title}* -->
        Page header <!-- common to all single entry school pages -->
      
        {if segment_3 == ""} <!-- /schools/{url_title} -->
          <div> <!-- tab_wrapper -->
            <div>Tabs</div> <!-- for following 6 page segments: each tab shows or injects content -->
            
            <div>Overview content</div>
            <div><a href="/schools/{url_title}/courses">Courses</a></div> <!-- injected on demand -->
            <div>Related students content</div>
            <div><a href="/schools/{url_title}/accommodation-travel#accommodation">Accommodation for {title}, {location}</a></div> <!-- injected on demand -->
            <div><a href="/schools/{url_title}/accommodation-travel#travel">Travelling to {title}, {location}</a></div> <!-- injected on demand -->
            <div><a href="/support/visas/{country}">Visa guidance for {country}</a></div> <!-- injected on demand -->
            <div><a href="/locations/{location}">About {location}</a></div> <!-- injected on demand -->
          </div>
        {/if}
      {/if}
      
      {if segment_3 == "courses"} <!-- /schools/{url_title}/courses -->
        <div>Related courses content</div>
      {/if}
      
      {if segment_3 == "accommodation-travel"} <!-- /schools/{url_title}/accommodation-travel -->
        <div>Accommodation content</div>
        <div>Travel content</div>
      {/if}
    <!-- /single -->
      Global footer <!-- includes snippets -->
    </body>
  • #2 / Aug 31, 2012 8:14am

    Jonathan Schofield

    175 posts

    Unless I’m way off the mark I think the essence of what I’m getting at is which of the following is generally best…

    Setup A: a single main query of exp:channel:entries derived from segment_2 in the page body (as above)

    {if segment_2 != ""}
    {exp:channel:entries}
      <!-- Do some stuff regardless of whether segment 3 is present or not -->
      {if segment_3 ==""}<!-- Do some stuff only if segment 3 is empty -->{/if}
      {if segment_3 =="foo"}<!-- Do some specific segment_3 stuff -->{/if}
    {/exp:channel:entries}
    {/if}

    Setup B: multiple queries of exp:channel:entries derived from segment_2 in the page body

    {if segment_2 != ""}
      {exp:channel:entries}
        <!-- Do some stuff regardless of whether segment 3 is present or not -->
      {/exp:channel:entries}
    {/if}
    {if segment_3 ==""}
      {exp:channel:entries}
        <!-- Do some stuff only if segment 3 is empty -->
      {/exp:channel:entries}
    {/if}
    {if segment_3 =="foo"}
      {exp:channel:entries}
        <!-- Do some specific segment_3 stuff -->
      {/exp:channel:entries}
    {/if}
  • #3 / Aug 31, 2012 9:32am

    Boyink!

    5011 posts

    Either approach will result in only one set of channel:entries tags being processed and involves roughly the same number of conditionals, so I think it will be a wash.

    Were it me I’d probably code them both up enough to do some a/b testing on though, with the output profiler and template debugging turned on to get more data about the results.

  • #4 / Aug 31, 2012 12:09pm

    Jonathan Schofield

    175 posts

    Thanks, Mike. That’s a good idea. I’ll give that a go.

  • #5 / Aug 31, 2012 2:47pm

    Shane Eckert

    7174 posts

    Hey Jonathan Schofield,

    Thank you for posting your question here on the ExpressionEngine forums.

    I am glad to see that Mike was able to help!!

    Is there anything I can do to help?

    Cheers,

  • #6 / Sep 03, 2012 9:30am

    Jonathan Schofield

    175 posts

    No, I’m good thanks Shane.

    For the record, I’ve gone with setup B and things are working more efficiently as a result.

  • #7 / Sep 03, 2012 9:45am

    Boyink!

    5011 posts

    Did you happen to document the differences?  I’d be curious to see them.

  • #8 / Sep 03, 2012 9:51am

    Jonathan Schofield

    175 posts

    No, I haven’t actually done A/B testing yet as I’ve managed to achieve better performance just by offloading some of the data into segment_3 dependent URLs.

    I am curious though too and will report back when I get the time to assess things more fully—hopefully this week.

  • #9 / Sep 05, 2012 3:34pm

    Dan Decker

    7338 posts

    Hi Jonathan,

    Please do! We love a good follow up.

    I’ll move this on over to Community Help to keep it open for discussion.

    Thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases