We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37747
    • 50 Posts
    Is anybody using any code with modx to check if the server is staging vs production? I want to call a single minified js/css on production but when developing locally (on MAMP) I want to call the individual js/css files.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      We've set this up on our hosting by cooking it into the vhosts: so for one domain you can set compression on (which compresses all CSS into a single optimized CSS file, same for all JS). For the dev domain's vhost, you can leave this off.
        • 6629
        • 60 Posts
        You could use a boolean context setting to differentiate between staging and production.
        Setting name: live, Type: Yes/No, Default: 0

        On your staging server set "live" to 0, on production to 1.
        Include your CSS like this:
        [[++live:is=`0`:then=`[[$stagingCSSChunk]]`:else=`[[$productionCSSChunk]]`]]

          • 3749
          • 24,544 Posts
          Or in a snippet in the template (again assuming there is a System Setting with the key ('live'):


          if ($modx->getOption('live', null, false) == true) {
              $modx->regClientCSS('file1.js');
              $modx->regClientCSS('file2.js');
          } else {
              $modx->regClientCSS('js-all-min.js');
          
          }


          Since it defaults to false, you only need the setting on the production/live install.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 37747
            • 50 Posts
            Thanks for the great suggestions guys, really appreciated! I went with the context setting with output modifiers and put it straight into the template (no chunk/snippet) just to keep readability of the code as good as possible. I am using this in the <head> for CSS and before the </body> for js and https://code.google.com/p/minify/ for minification, this is what the code looks like in case it helps somebody in the future:

                [[++live:is=`0`:then=`
                  <!-- call individual staging files -->
                `:else=`
                  <!-- call single compressed file -->
                `]]