Skip to content

Instantly share code, notes, and snippets.

@brokyzz
Created February 22, 2015 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brokyzz/469f896cde74ed0248b2 to your computer and use it in GitHub Desktop.
Save brokyzz/469f896cde74ed0248b2 to your computer and use it in GitHub Desktop.
Combine and minify .js in php
<?php
header('Content-type: text/javascript');
ob_start("compress");
function compress( $minify )
{
/* remove comments */
$minify = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $minify);
/* remove tabs, spaces, newlines, etc. */
$minify = str_replace(array("\r\n","\r","\t","\n",' ',' ',' '), '', $minify);
/* remove other spaces before/after ) */
$minify = preg_replace(array('(( )+\))','(\)( )+)'), ')', $minify);
return $minify;
}
/* Js files for combining */
include('custom.js');
include('custom2.js');
ob_end_flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment