How to minify JS in PHP easily...Or something else
        Posted  
        
            by 
                RickyAYoder
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by RickyAYoder
        
        
        
        Published on 2012-06-12T15:52:51Z
        Indexed on 
            2012/06/12
            16:40 UTC
        
        
        Read the original article
        Hit count: 393
        
I've done some looking around, but I'm still confused a bit.
I tried Crockford's JSMin, but Win XP can't unzip the executable file for some reason.
What I really want though is a simple and easy-to-use JS minifier that uses PHP to minify JS code--and return the result.
The reason why is because: I have 2 files (for example) that I'm working between: scripts.js and scripts_template.js
scripts_template is normal code that I write out--then I have to minify it and paste the minified script into scripts.js--the one that I actually USE on my website.
I want to eradicate the middle man by simply doing something like this on my page:
<script type="text/javascript" src="scripts.php"></script>
And then for the contents of scripts.php:
<?php include("include.inc"); header("Content-type:text/javascript"); echo(minify_js(file_get_contents("scripts_template.js")));
This way, whenever I update my JS, I don't have to constantly go to a website to minify it and re-paste it into scripts.js--everything is automatically updated.
Yes, I have also tried Crockford's PHP Minifier and I've taken a look at PHP Speedy, but I don't understand PHP classes just yet...Is there anything out there that a monkey could understand, maybe something with RegExp?
How about we make this even simpler?
I just want to remove tab spaces--I still want my code to be readable.
It's not like the script makes my site lag epically, it's just anything is better than nothing.
Tab removal, anyone? And if possible, how about removing completely BLANK lines?
© Stack Overflow or respective owner