Skip to content

Commit

Permalink
Prepping 2.1.4 beta release. Issue 185, More helpful Builder messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclay committed Jul 8, 2010
1 parent 15de686 commit 5e0a7b1
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 38 deletions.
15 changes: 15 additions & 0 deletions HISTORY.txt
@@ -1,5 +1,20 @@
Minify Release History

Version 2.1.4
* Cookie/bookmarklet-based debug mode. No HTML editing!
* Allows 1 file to be missing w/o complete failure
* Combine multiple groups and files in single URI
* More useful HTML helpers for writing versioned URIs
* More detailed error logging, including minifier exceptions
* Builder offers more helpful messages/PHP environment warnings
* Bypass minification based on filename pattern. e.g. foo.min.js / foo-min.css
* JSMin won't choke on common Closure compiler syntaxes (i+ ++j)
* Better caching in IE6
* Cache ids are influenced by group/file names
* Debug mode for Javascript doesn't break on common XPath strings (Prototype 1.6)
* Removed annoying maxFiles limit
* mbstring.func_overload usage is safer

Version 2.1.3
* HTTP fixes
* ETag generation now valid (different when gzipped)
Expand Down
8 changes: 8 additions & 0 deletions README.txt
Expand Up @@ -8,6 +8,14 @@ and tell clients to cache the file for a period of time.
More info: http://code.google.com/p/minify/


WORDPRESS USER?

These WP plugins integrate Minify into WordPress's style and script hooks to
get you set up faster.
http://wordpress.org/extend/plugins/wp-minify/
http://wordpress.org/extend/plugins/w3-total-cache/


UPGRADING

See UPGRADING.txt for instructions.
Expand Down
25 changes: 19 additions & 6 deletions min/README.txt
Expand Up @@ -82,7 +82,7 @@ This pre-selects the following files to be combined under the key "js":

You can now serve these files with this simple URL:
http://example.com/min/?g=js


GROUPS: SPECIFYING FILES OUTSIDE THE DOC_ROOT

Expand All @@ -99,22 +99,35 @@ return array(
);


COMBINE MULTIPLE GROUPS AND FILES IN ONE URL

E.g.: http://example.com/min/?g=js&f=more/scripts.js

Separate group keys with commas:
http://example.com/min/?g=baseCss,css1&f=moreStyles.css


FAR-FUTURE EXPIRES HEADERS

Minify can send far-future (one year) Expires headers. To enable this you must
add a number to the querystring (e.g. /min/?g=js&1234 or /min/f=file.js&1234)
and alter it whenever a source file is changed. If you have a build process you
can use a build/source control revision number.

If you serve files as a group, you can use the utility function Minify_groupUri()
to get a "versioned" Minify URI for use in your HTML. E.g.:
You can alternately use the utility function Minify_getUri() to get a "versioned"
Minify URI for use in your HTML. E.g.:

<?php
// add /min/lib to your include_path first!
require $_SERVER['DOCUMENT_ROOT'] . '/min/utils.php';

$jsUri = Minify_groupUri('js');
echo "<script type='text/javascript' src='{$jsUri}'></script>";
$jsUri = Minify_getUri('js'); // a key in groupsConfig.php
echo "<script src='{$jsUri}'></script>";

$cssUri = Minify_getUri(array(
'//css/styles1.css'
,'//css/styles2.css'
)); // a list of files
echo "<link rel=stylesheet href='{$cssUri}'>";


DEBUG MODE
Expand Down
64 changes: 47 additions & 17 deletions min/builder/index.php
Expand Up @@ -29,12 +29,34 @@
exit();
}

$setIncludeSuccess = set_include_path(dirname(__FILE__) . '/../lib' . PATH_SEPARATOR . get_include_path());
// we do it this way because we want the builder to work after the user corrects
// include_path. (set_include_path returning FALSE is OK).
try {
require_once 'Solar/Dir.php';
} catch (Exception $e) {
if (! $setIncludeSuccess) {
echo "Minify: set_include_path() failed. You may need to set your include_path "
."outside of PHP code, e.g., in php.ini.";
} else {
echo $e->getMessage();
}
exit();
}
require 'Minify.php';

$cachePathCode = '';
if (! isset($min_cachePath)) {
$detectedTmp = rtrim(Solar_Dir::tmp(), DIRECTORY_SEPARATOR);
$cachePathCode = "\$min_cachePath = " . var_export($detectedTmp, 1) . ';';
}

ob_start();
?>
<!DOCTYPE HTML>
<title>Minify URI Builder</title>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<style type="text/css">
<style>
body {margin:1em 60px;}
h1, h2, h3 {margin-left:-25px; position:relative;}
h1 {margin-top:0;}
Expand All @@ -54,23 +76,25 @@
</style>
<body>
<?php if ($symlinkOption): ?>
<div class=topNote><strong>Note:</strong> It looks like you're running Minify in a user
<div class=topNote><strong>Note:</strong> It looks like you're running Minify in a user
directory. You may need the following option in /min/config.php to have URIs
correctly rewritten in CSS output:
<br><textarea id=symlinkOpt rows=3 cols=80 readonly><?php echo htmlspecialchars($symlinkOption); ?></textarea>
</div>
<?php endif; ?>

<p class=topWarning id=jsDidntLoad><strong>Uh Oh.</strong> Minify was unable to
serve the Javascript for this app. To troubleshoot this,
serve Javascript for this app. To troubleshoot this,
<a href="http://code.google.com/p/minify/wiki/Debugging">enable FirePHP debugging</a>
and request the <a id=builderScriptSrc href=#>Minify URL</a> directly. Hopefully the
FirePHP console will report the cause of the error.
</p>

<?php if (! isset($min_cachePath)): ?>
<p class=topNote><strong>Note:</strong> You can set <code>$min_cachePath</code>
in /min/config.php to slightly improve performance.</p>
<?php if ($cachePathCode): ?>
<p class=topNote><strong>Note:</strong> <code><?php echo
htmlspecialchars($detectedTmp); ?></code> was discovered as a usable temp directory.<br>To
slightly improve performance you can hardcode this in /min/config.php:
<code><?php echo htmlspecialchars($cachePathCode); ?></code></p>
<?php endIf; ?>

<p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
Expand Down Expand Up @@ -138,8 +162,8 @@
<h3>Debug Mode</h3>
<p>When /min/config.php has <code>$min_allowDebugFlag = <strong>true</strong>;</code>
you can get debug output by appending <code>&amp;debug</code> to a Minify URL, or
by sending the cookie <code>minDebug=&lt;match&gt;</code>, where <code>minDebug=&lt;match&gt;</code>
should match the Minify URIs you'd like to debug. This bookmarklet will allow you to
by sending the cookie <code>minDebug=&lt;match&gt;</code>, where <code>&lt;match&gt;</code>
should be a string in the Minify URIs you'd like to debug. This bookmarklet will allow you to
set this cookie.</p>
<p><a id=bm2>Minify Debug</a> <small>(right-click, add to bookmarks)</small></p>

Expand All @@ -149,13 +173,20 @@
<p>Need help? Check the <a href="http://code.google.com/p/minify/w/list?can=3">wiki</a>,
or post to the <a class=ext href="http://groups.google.com/group/minify">discussion
list</a>.</p>
<p><small>This app is minified :)</small></p>

<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<p><small>Powered by Minify <?php echo Minify::VERSION; ?></small></p>

<script type="text/javascript">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script>
$(function () {
// give Minify a few seconds to serve _index.js before showing scary red warning
$('#jsDidntLoad').hide();
setTimeout(function () {
if (! window.MUB) {
// Minify didn't load
$('#jsDidntLoad').show();
}
}, 3000);

// detection of double output encoding
var msg = '<\p class=topWarning><\strong>Warning:<\/strong> ';
var url = 'ocCheck.php?' + (new Date()).getTime();
Expand Down Expand Up @@ -183,7 +214,7 @@
});
});
</script>
<script type="text/javascript">
<script>
// workaround required to test when /min isn't child of web root
var src = location.pathname.replace(/\/[^\/]*$/, '/_index.js').substr(1);
src = "../?f=" + src;
Expand All @@ -197,8 +228,6 @@
$content = ob_get_clean();

// setup Minify
set_include_path(dirname(__FILE__) . '/../lib' . PATH_SEPARATOR . get_include_path());
require 'Minify.php';
if (0 === stripos(PHP_OS, 'win')) {
Minify::setDocRoot(); // we may be on IIS
}
Expand All @@ -212,9 +241,10 @@
'content' => $content
,'id' => __FILE__
,'lastModifiedTime' => max(
// regenerate cache if either of these change
// regenerate cache if any of these change
filemtime(__FILE__)
,filemtime(dirname(__FILE__) . '/../config.php')
,filemtime(dirname(__FILE__) . '/../lib/Minify.php')
)
,'minifyAll' => true
,'encodeOutput' => $encodeOutput
Expand Down
2 changes: 1 addition & 1 deletion min/config.php
Expand Up @@ -62,7 +62,7 @@
* second line. The third line might work on some Apache servers.
*/
$min_documentRoot = '';
//$min_documentRoot = substr(__FILE__, 0, strlen(__FILE__) - 15);
//$min_documentRoot = substr(__FILE__, 0, -15);
//$min_documentRoot = $_SERVER['SUBDOMAIN_DOCUMENT_ROOT'];


Expand Down
7 changes: 3 additions & 4 deletions min/lib/Minify/CommentPreserver.php
Expand Up @@ -30,8 +30,7 @@ class Minify_CommentPreserver {
* Process a string outside of C-style comments that begin with "/*!"
*
* On each non-empty string outside these comments, the given processor
* function will be called. The first "!" will be removed from the
* preserved comments, and the comments will be surrounded by
* function will be called. The comments will be surrounded by
* Minify_CommentPreserver::$preprend and Minify_CommentPreserver::$append.
*
* @param string $content
Expand Down Expand Up @@ -65,7 +64,7 @@ public static function process($content, $processor, $args = array())
* @param string $in input
*
* @return array 3 elements are returned. If a YUI comment is found, the
* 2nd element is the comment and the 1st and 2nd are the surrounding
* 2nd element is the comment and the 1st and 3rd are the surrounding
* strings. If no comment is found, the entire string is returned as the
* 1st element and the other two are false.
*/
Expand All @@ -79,7 +78,7 @@ private static function _nextComment($in)
}
$ret = array(
substr($in, 0, $start)
,self::$prepend . '/*' . substr($in, $start + 3, $end - $start - 1) . self::$append
,self::$prepend . '/*!' . substr($in, $start + 3, $end - $start - 1) . self::$append
);
$endChars = (strlen($in) - $end - 2);
$ret[] = (0 === $endChars)
Expand Down
4 changes: 2 additions & 2 deletions min/lib/Minify/Controller/Base.php
Expand Up @@ -52,7 +52,7 @@ public function getDefaultMinifyOptions() {
,'quiet' => false // serve() will send headers and output
,'debug' => false

// if you override this, the response code MUST be directly after
// if you override these, the response codes MUST be directly after
// the first space.
,'badRequestHeader' => 'HTTP/1.0 400 Bad Request'
,'errorHeader' => 'HTTP/1.0 500 Internal Server Error'
Expand Down Expand Up @@ -148,7 +148,7 @@ public static function checkAllowDirs($file, $allowDirs, $uri)
}
throw new Exception("File '$file' is outside \$allowDirs. If the path is"
. " resolved via an alias/symlink, look into the \$min_symlinks option."
. " E.g. \$min_symlinks = array('/" . dirname($uri) . "' => '" . dirname($file) . "');");
. " E.g. \$min_symlinks['/" . dirname($uri) . "'] = '" . dirname($file) . "';");
}

public static function checkNotHidden($file)
Expand Down
2 changes: 1 addition & 1 deletion min_unit_tests/_test_files/css/comments.min.css
@@ -1,3 +1,3 @@

/* YUI Compressor style comments are preserved */
/*! YUI Compressor style comments are preserved */
body{background:#fff url(/path/to/image.gif) repeat-y}
2 changes: 1 addition & 1 deletion min_unit_tests/_test_files/html/before.min.html
Expand Up @@ -8,7 +8,7 @@
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}</script> <script type="text/javascript">/*<![CDATA[*/var i=0;while(++i<10)
{}/*]]>*/</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">/*<![CDATA[*/(i<1);/*]]>*/</script> <!--[if IE 6]><style type="text/css">/*<![CDATA[*/
/* copyright: you'll need CDATA for this < & */
/*! copyright: you'll need CDATA for this < & */
body{background:white}/*]]>*/</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*/css
hack{}/**/ /*/*/css
hack{}/**/css
Expand Down
2 changes: 1 addition & 1 deletion min_unit_tests/_test_files/html/before2.min.html
Expand Up @@ -8,7 +8,7 @@
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}</script> <script type="text/javascript">var i=0;while(++i<10)
{}</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">(i<1);</script> <!--[if IE 6]><style type="text/css">
/* copyright: you'll need CDATA for this < & */
/*! copyright: you'll need CDATA for this < & */
body{background:white}</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*/css
hack{}/**/ /*/*/css
hack{}/**/css
Expand Down
2 changes: 1 addition & 1 deletion min_unit_tests/_test_files/minify/minified.css
@@ -1,5 +1,5 @@
@import url(/more.css);body,td,th{font-family:Verdana,"Bitstream Vera Sans",sans-serif;font-size:12px}.nav{margin-left:20%}#main-nav{background-color:red;border:1px
solid #0f7}div#content
h1+p{padding-top:0;margin-top:0}@media all and (min-width: 640px){#media-queries-1{background-color:#0f0}}@media screen and (max-width: 2000px){#media-queries-2{background-color:#0f0}}
/* YUI Compressor style comments are preserved */
/*! YUI Compressor style comments are preserved */
body{background:#fff url(/path/to/image.gif) repeat-y}
8 changes: 4 additions & 4 deletions min_unit_tests/test_Minify_CommentPreserver.php
Expand Up @@ -9,10 +9,10 @@ function test_Minify_CommentPreserver()
global $thisDir;

$inOut = array(
'/*!*/' => "\n/**/\n"
,'/*!*/a' => "\n/**/\n1A"
,'a/*!*//*!*/b' => "2A\n/**/\n\n/**/\n3B"
,'a/*!*/b/*!*/' => "4A\n/**/\n5B\n/**/\n"
'/*!*/' => "\n/*!*/\n"
,'/*!*/a' => "\n/*!*/\n1A"
,'a/*!*//*!*/b' => "2A\n/*!*/\n\n/*!*/\n3B"
,'a/*!*/b/*!*/' => "4A\n/*!*/\n5B\n/*!*/\n"
);

foreach ($inOut as $in => $expected) {
Expand Down

0 comments on commit 5e0a7b1

Please sign in to comment.