We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37032
    • 64 Posts
    Hi,

    Which option do you think is best and why when it comes to creating templates for your sites.

    Alternative 1 seems to be most common but it requires more logic than alternative 2 (at least if you have multiple page types that is dependent on different stylesheets and scripts). Does anyone know if this there is a notable difference in performance between the two?

    Alt 1 (shell)
    [[$header? &customCSS=`[[$aCustomCSS]]`]]
    
    <div id="content">
            [[*content]]
    </div>
    
    [[$footer? &customScript=`[[$aCustomScript]]`]]
    


    Alt 2
    [[$head]]
    <link rel="stylesheet" href="a-page-specific.css">
    </head>
    <body>
    
    <div id="content">
            [[*content]]
    </div>
    
    [[$footer]]
    [[$script]]
    <script src="a-custom-script.js"></script>
    </body>
    </html>
    


    What is your opinion?

    // T
      • 10484
      • 32 Posts
      I would recommend "Alt 2" for your final draft. If you're still developing, it might be easier to compile everything into oversimplified chunks (like in "Alt 1"), but that adds a cost to the parsing time. If your site has lots of data or heavy traffic, it's best to scale your site accordingly for performance. I used to break things down significantly for creating my templates to avoid having to edit each template when making a small change, but after killing MySQL a few hundred times on a large news site, it came to my attention that it simply wasn't worth saving me 10 minutes of minor edits if the site was going down for hours at a time. Here's an example of how my markup would look.

      I would compile everything into a single chunk:

      [[$modx]]


      This is all that would be in my template. There, that chunk would break down to something like:

      [[$head]]
      [[$[[*template]]]]
      [[$footer]]


      That way, I just made chunks named after the ID for each varying template. This allowed me to modify the head or footer chunks, but it was a hog on the cache, ultimately causing several performance issues. It saved me hours when building the site layout, but now, I ripped as many chunks out as possible and replaced it with static code. I even got rid of basic things, like [[++site_url]] and replaced it with just text.

      In summation, I would always recommend keeping your markup on the lighter side for the sake of performance. When developing, it's okay, but with live production sites, you'll want to cut it back and fill your templates out a lot more, using caching where applicable. Good chance, you'll have ironed out all the minor changes, but making small adjustments in the future to multiple templates is much simpler than having a universal template with a lot of conditional statements. The less parsing the server has to do, the less errors you'll likely have.

      Development and production stages have different methods of optimizing.

      Hope this helped answer your question smiley
        Garret Overstreet
        Business and Marketing Consultant
        • 37032
        • 64 Posts
        Quote from: garretoverstreet at Sep 17, 2013, 01:37 AM
        I would recommend "Alt 2" for your final draft. If you're still developing, it might be easier to compile everything into oversimplified chunks (like in "Alt 1"), but that adds a cost to the parsing time. If your site has lots of data or heavy traffic, it's best to scale your site accordingly for performance. I used to break things down significantly for creating my templates to avoid having to edit each template when making a small change, but after killing MySQL a few hundred times on a large news site, it came to my attention that it simply wasn't worth saving me 10 minutes of minor edits if the site was going down for hours at a time. Here's an example of how my markup would look.

        I would compile everything into a single chunk:

        [[$modx]]


        This is all that would be in my template. There, that chunk would break down to something like:

        [[$head]]
        [[$[[*template]]]]
        [[$footer]]


        That way, I just made chunks named after the ID for each varying template. This allowed me to modify the head or footer chunks, but it was a hog on the cache, ultimately causing several performance issues. It saved me hours when building the site layout, but now, I ripped as many chunks out as possible and replaced it with static code. I even got rid of basic things, like [[++site_url]] and replaced it with just text.

        In summation, I would always recommend keeping your markup on the lighter side for the sake of performance. When developing, it's okay, but with live production sites, you'll want to cut it back and fill your templates out a lot more, using caching where applicable. Good chance, you'll have ironed out all the minor changes, but making small adjustments in the future to multiple templates is much simpler than having a universal template with a lot of conditional statements. The less parsing the server has to do, the less errors you'll likely have.

        Development and production stages have different methods of optimizing.

        Hope this helped answer your question smiley

        Thanks for your long and detailed answer. smiley

        I agree that a master template saves you a lot of time when building the page, but again, it does require more logic (bad for performance). The second alternative requires a bit more care and work when updating the global structure, but on the other hand it can achieve the same result without almost any logic. It is also better performance wise to include shared chunks When you need them, instead of having logic to decide wether it should be displayed or not.
          • 37032
          • 64 Posts
          Ran some tests today and I actually got better results with alternative 1 than 2. Not what I've expected. :S I also tried your approach with a single chunk and that one was notably slower than the other two.