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

    Recently I discovered that modx does not play well with minified js files that exist as a text/javascript resource in the manager. I just want to gather some opinions before posting to Jira

    So if you create a text/javascript file in modx and paste the minified version of jquery you will get errors because modx will remove

    [++e]);return a},trim:function(a){return(a||"").replace(Sa,"")},makeArray:function(a,b){b=b||[];if(a!=null)a.length==null||typeof a==="string"||c.isFunction(a)||typeof a!=="function"&&a.setInterval?ba.call(b,a):c.merge(b,a);return b},inArray:function(a,b){if(b.indexOf)return b.indexOf(a);for(var d=0,f=b.length;d<f;d++)if(b[d]===a)return d;return-1},merge:function(a,b){var d=a.length,f=0;if(typeof b.length==="number")for(var e=b.length;f<e;f++)a[d++]


    because the string starts with [++ and ends with ++]


    It seems that most of the Revo tags are OK, so a solution would be to change the default Evo tags to match the Revo tags.
    The only problem with Revo is the snippet tag which I hope can be change before the RC. Maybe something like [[$$ can be ussed instead of [[

    Thank You
      • 21257 MODX Staff
      • 730 Posts
      As a workaround, what about substituting occurrances of [++e] with [eval(’++e’)] and f++ with eval(’f++’).
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 22303 MODX Staff
        • 10,725 Posts
        TBH, running JS files as MODx Resources destroys all the benefits of browser mechanisms for caching Javascript in the first place, and it certainly wouldn’t help much compressing that content.
          • 5340
          • 1,624 Posts
          Quote from: netProphET at Feb 16, 2010, 03:26 PM

          As a workaround, what about substituting occurrances of [++e] with [eval(’++e’)] and f++ with eval(’f++’).

          I’m, not sure it’s a good solution. Every time I upgrade any js files I need to search for strings that could break the js functionality.

          Quote from: OpenGeek at Feb 16, 2010, 04:37 PM

          TBH, running JS files as MODx Resources destroys all the benefits of browser mechanisms for caching Javascript in the first place, and it certainly wouldn’t help much compressing that content.

          Can you please give me more details as why "MODx Resources destroys all the benefits of browser mechanisms for caching Javascript".
          Also have a look at MinJs (signature for link), that’s how discovered the problem. Iwas trying to concatenate multiple minimized files into one file. I had jquery + jquery ui + mysite.js.

          Thx
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: cipa at Feb 16, 2010, 07:08 PM

            Can you please give me more details as why "MODx Resources destroys all the benefits of browser mechanisms for caching Javascript".
            Because instead of a simple Javascript file served by the web server that can be cached by the browser, you are bootstrapping MODx (and the PHP engine) on every request for that Javascript file. It is much more efficient to compress/concatenate your Javascript and simply serve it as a file from the web server.
              • 5340
              • 1,624 Posts
              Since the file I send to the server has a Content-Type of text/javascript the browser should not care if it’s a file on the server or a generated file. I might be wrong. Shouldn’t all be about the headers sent to the browser?

              Also the javascript file I generate is cached by modx, it shouldn’t be much difference between my file and a file on the server. I never measured the how much time is lost reading a modx cache file but it shouldn’t be that bad.

              Again I agree that a server solution is faster then a modx solution but even with a solution like Minify you still have to do some php processing and read the generated cache file generated.

              Thx OpenGeek for your answers. I’m just trying to understand why a modx solution based on Minify is worse then the Minify solution.

                • 22303 MODX Staff
                • 10,725 Posts
                Does everyone understand that launching any PHP script is much more expensive in terms of processing than having the web server just serve a file? It doesn’t matter if it is a cached MODx Resource or not; the process of launching the PHP engine and including/executing all of the PHP files required to bootstrap MODx is still way more intensive than serving a static Javascript file, no matter how efficient we make that process.

                Also, in Evo, unless you set the headers for the Javascript in your snippets, browsers likely will not be able to cache it properly. In Revolution, you can have it set custom headers per Content Type to address this.
                  • 5340
                  • 1,624 Posts
                  I wasn’t aware of how much modx/php impacts the timing.

                  I’ll reconsider the way I optimize my css an js.