We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32025
    • 305 Posts
    In a new MODx installation and I have a very crowded head section. The reason is that I have 14 different image galleries. Each gallery requires 3 lines of javascript in the header, but I was able to slim it down to 2 lines per gallery by re-using one of the lines. That means I have to add 29 javascript lines to the header of my gallery template. I already have a homePage template (with 1 of these galleries), a regular template for the rest of my site with none of these gallery javascript lines, and last one template for all my image gallery pages, which is my problem.

    The image gallery template header (which is my problem) currently looks like this:
    
    <head>
    <meta charset="utf-8">
    <title>My Site - [[*pagetitle]]</title>
    <base href="[[++site_url]]" />
    <link href="[[++site_url]]css/landScape.css" rel="Stylesheet" type="text/css">
    <link href="[[++site_url]]Nav%20Menu.css3prj_files/css3menu1/style.css" rel="stylesheet" type="text/css" />
    
    <!-- Start slideshow HEAD section -->
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/app/web/js/jabb-0.3.js"></script>
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=2"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=2" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=3"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=3" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=4"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=4" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=5"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=5" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=6"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=6" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=7"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=7" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=8"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=8" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=9"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=9" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=10"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=10" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=11"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=11" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=12"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=12" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=13"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=13" />
    
    <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=14"></script>
    <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=14" />
    <!-- End slideshow HEAD section -->
    
    </head>
    
    


    On each corresponding gallery page I have coding that then displays the gallery on that specific page. For instance on the gallery #2 page this is my coding (in the content section):
    <h1>Design Gallery</h1>
    <p id="galleryShow"><script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=load&id=2"></script></p>


    This in the content area of each page and combined with the header javscript (which is my crowding issue) each page displays the correct gallery properly.

    So having to put all the javascript lines in only one template for all my galleries seems is what is leading to my crowding problem.

    I am assuming having this much to load is going to bog down lots of devices and someone with a slow internet connection but I am not sure. I already have 3 templates, what am I to do create a new template for each gallery page? Is there a way that I can add 3 lines of these into the header based upon the page? Maybe a template variable?

    I just don't know what to do short of creating a new template for each and every gallery page? But that just seems wrong. I feel I am overlooking something very simple. Any suggestions to help clean this up?
      Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Would this work?
      <script type="text/javascript" src="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadJs&id=[[*id]]"></script>
      <link type="text/css" rel="stylesheet" href="[[++site_url]]core/components/gallery/index.php?controller=Front&action=loadCss&id=[[*id]]" />
      


      You should always try to put Javascript links at the bottom of the HTML body. The browser blocks (stops whatever it's doing and waits until the file is downloaded) when it sees a link to Javascript.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32025
        • 305 Posts
        Great Idea. The built in resource ID's for my gallery pages are from 2 - 14. The resource ID's for the corresponding pages numbers were 10 - 22.

        I ended up re-arrange all my pages numbers to match my gallery ID's it was an hour or so work which wasn't bad, but is a very clean solution by comparison. The gallery page numbers now have the same as the javascript page number of 2 - 14. Excellent solution now I only have the 3 lines of code in the bottom of my header for each corresponding page.

        BTW, thank you for letting me know javascript should always go on the bottom of the header. I usually put it there, but it's nice to know anyway.

        One last question: I am assuming I should disable the Cacheable box for each gallery page correct? Since it puts the automatically generated page resource ID into the URL. The reason I ask is since it's a photo gallery cache would help becuase each image is in fairly high def. I will leave cahe unchecked if it will affect adding these sequence numbers into the URL correctly, but would prefer to have cache enabled so the galleries load faster. What do you suggest?
          Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It's very rare for there to be any benefit to a page not being cached. If something is dynamic like a display of the current date, a menu that depends on a user's login status or a form's POST values, the snippet involved can be uncached.

          Just for your information, if the resource IDs were not useful for something like this you could have used a TV to hold the id value - just don't name the TV "id" so it won't get confused with the resource ID value. Something like "gallery_id".
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 32025
            • 305 Posts
            I think I will take your recommendation and cache all the gallery pages.

            The reouces ID's your provided were ideal and work like a charm. Was thinking I could probably use a TV but I am unfamiliar with TV's. I keep reading about them, but don't seem to ever find a reason to use one (other than on my FormZ).

            Thank you once again Sottwell. Your time and effort is much appreciated!
              Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/