SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)

    Offline Javascript Minifier

    I've seen a fair number of web-based javascript minifiers, but I have no idea how they are in terms of quality and whatnot, or if they will be around tomorrow or next week.

    So, I was looking for an offline minifier and was wondering what some of you preferred as your JS minifier of choice?
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use http://developer.yahoo.com/yui/compressor/

    My 5 min hack interface
    PHP Code:
    <?php
    header
    ('content-type: text/html;charset=utf-8');
    ?>

    <form enctype="multipart/form-data" method=post action=>
    <input type=radio name=type value=js checked> js<br>
    <input type=radio name=type value=css> css<br>
    <input type=file name=upload> or<br>
    <textarea name=contents rows=20 cols=100></textarea>
    <input type=submit>
    </form>


    <?php
    $java_executable 
    'java';
    $yui_executable 'C:\java\yui\yui.jar';

    if (@
    $_POST) {
        if (@
    $_FILES['upload']['tmp_name']) {
            
    $source $_FILES['upload']['tmp_name'];
        } else {
            
    file_put_contents($source tempnam('/tmp''min'), $_POST['contents']);
        }
        
        
    $cmd sprintf('%s -jar %s --type %s %s',
            
    $java_executable,
            
    escapeshellarg($yui_executable),
            
    $_POST['type'],
            
    escapeshellarg($source)
        );
        
        
    $result shell_exec($cmd);
        
    $before filesize($source);
        
    $after strlen($result);
        
        
    printf('<b>%s<br>before: %d<br>after:%d<br>diff:%d (%.2f)</b>',
            
    $cmd$before$after$before $after,  $after $before);
        
    printf('<br><textarea rows=20 cols=100>%s</textarea>'htmlspecialchars($result));
        
    unlink($source);
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •