We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25483
    • 741 Posts
    At this moment I use "minify" http://code.google.com/p/minify/ on all my web projects. I do this to speed up the website so that the site is as fast as possible.
    The ’problem’ is that I need to build in minify myself, where the best solution is that a plugin handles this for me.

    I’m not sure if something like minify can be turned into a plugin that scans the output of the pages for CSS and JS calls and then combine them into a call that activates minify. Can someone tell me if this possible and maybe put me in the good direction so that I can try to make a plugin like this?

    By the way; it doesn’t have to be "minify", I just want a option to optimize/minify css and js automaticly. I also found "CSS JS Booster" http://github.com/Schepp/CSS-JS-Booster maybe it is a better solution to start with?
      with regards,

      Ronald Lokers
      'Front-end developer' @ h2o Media

      • 25483
      • 741 Posts
      Anyone there that likes the idea and wants to help me?
        with regards,

        Ronald Lokers
        'Front-end developer' @ h2o Media

      • Very good idea Ronald, don’t have much bandwidth now but would love to see a plugin sorted out to handle this task.
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 3749
          • 24,544 Posts
          This wouldn’t be hard to do, but parsing the page and running the minify code each time the page is accessed kind of defeats the whole purpose.
            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
            • 25483
            • 741 Posts
            @BobRay: How would you setup something like this? Would you cache the css and js code after minified?

            What I do now is that I run everything through "minify" and that php script gives back the cached version if it is there. Are we possible to put the link to the cached version directly into the modx database so that modx doesn’t need to parse everything what is done before?
              with regards,

              Ronald Lokers
              'Front-end developer' @ h2o Media

            • I don’t use minify but i do compress the js by putting an index.php file in my template directory which regroup all the needed libs and gzip them.

              Then in my template i load it automatically

              //Loading the index file in my template directory
              <script type="text/javascript" src="[(base_url)]/assets/templates/mytemplates/libs/"></script>
              


              I’m using ExtJS on front end and it reduce the size from 685kb to 135kb. If someone is interested, here a sample code:

              <?php
              ob_start ("ob_gzhandler");
              header("Content-type: text/javascript; charset: UTF-8");
              header("Cache-Control: must-revalidate");
              $offset = 60 * 60 ; // Duration in seconds before the cache expires
              $ExpStr = "Expires: " .
              gmdate("D, d M Y H:i:s",
              time() + $offset) . " GMT";
              header($ExpStr);
              
              // Javascript files to compress
              include $_SERVER['DOCUMENT_ROOT'].'/assets/libs/extjs/adapter/ext/ext-base.js';
              include $_SERVER['DOCUMENT_ROOT'].'/assets/libs/extjs/ext-all.js';
              


              Now i don’t know if it’s possible to use this method in combination with MODx function getRegisteredClientScripts(), it could be useful.



                • 5340
                • 1,624 Posts
                I was working on a similar idea but didn’t get the chance to work on it.

                1. create a css document in manager
                2. as content put a snippet like [[minifyCss? &files=`reset.css,site.css`]]

                The snippet will get all the css files concatenate them and remove any spaces.
                The file will only be generated when you clear the cache.

                I was thinking to do something similar with JS.
                • I think that’s a great approach cipa.
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 15082
                    • 195 Posts
                    I’ve done something similar for JavaScript:
                    In one project I’ve a couple of chunks containing JS for different purposes.
                    I’ve taken and patched the solution from here to combine them into a single "file" (called via his FURL).
                    Additionally I’ve added a call to JSMIN to reduce the "filesize".

                    [tt]chunkListParser[/tt] (snippet)
                    <?php
                    $minify = ( isset($minify) && $minify == 'true' ) ? true : false;
                    
                    $ar_chunks = split(',',$chunks);
                    $ar_chunks = array_unique($ar_chunks);
                    
                    $output = '';
                    
                    foreach ($ar_chunks as $chunk) {
                    	if ($chunk != '') {
                    		$c = $modx->getChunk($chunk);
                    		if ($c) $output .= $c . "\r\n";  //linebreak added by JUSI
                    	}
                    }
                    
                    if ($output != '' && isset($wrapperdiv)) {
                    	$output = '<div id="'.$wrapperdiv.'">'.$output.'</div>';
                    }
                    if ($minify == true) {
                    	require 'assets/snippets/bv-jsmin/jsmin-1.1.1.php';
                    	$output =  JSMin::minify($output);
                    }
                    
                    return $output;
                    ?>


                    [tt]getChunks[/tt] (snippet)
                    <?php
                    $q_chunks = $modx->db->query('
                    	SELECT
                    		chunk.*
                    	FROM '.$modx->getFullTableName('site_htmlsnippets').' AS chunk
                    		INNER JOIN '.$modx->getFullTableName('categories').' AS category
                    		ON chunk.category = category.id
                    	WHERE
                    		category.category IN ("'.$category.'")
                    	ORDER BY
                    		name
                    ');	
                    
                    $ar_chunks = array();
                    while ($row = $modx->db->getRow($q_chunks)) {
                    	$ar_chunks[] = $row['name'];
                    }
                    
                    $l_chunks = implode(",",$ar_chunks);  //splitter character changed from "||" to "," by JUSI
                    return $l_chunks;
                    ?>


                    [tt]combined.js[/tt] (document)
                    [[chunkListParser?chunks=`[[getChunks? &category=`bv js` ]]` &minify=`true` ]]
                    


                    Greetz
                    JUSI
                    • Not hijacking the thread, just OOT a little:
                      Quote from: jusicgn at Dec 02, 2009, 04:12 PM

                      [tt]getChunks[/tt] (snippet)

                      Is this $modx->getChunk()? or a new snippet?
                      Do we have a convention about naming, yet?
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        www.virtudraft.com

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                        Maintainter/contributor of Babel

                        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.