From c177ea2c220ee7b9ea856cf1119d2c03f1b250a7 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Sat, 13 Sep 2008 21:48:53 +0000 Subject: [PATCH] mod_rewrite allows Minify URIs w/o "?" builder/_index.js checks for this feature --- min/.htaccess | 2 ++ min/builder/_index.js | 25 +++++++++++++++++++-- min/builder/bm.js | 6 ++++- min/builder/index.php | 46 +++++++++++++++++++++++++------------- min/builder/rewriteTest.js | 1 + 5 files changed, 62 insertions(+), 18 deletions(-) create mode 100644 min/.htaccess create mode 100644 min/builder/rewriteTest.js diff --git a/min/.htaccess b/min/.htaccess new file mode 100644 index 0000000..34903dc --- /dev/null +++ b/min/.htaccess @@ -0,0 +1,2 @@ +RewriteEngine on +RewriteRule ^([a-z]=.*) index.php?$1 [L,NE] \ No newline at end of file diff --git a/min/builder/_index.js b/min/builder/_index.js index e48064a..af50a85 100644 --- a/min/builder/_index.js +++ b/min/builder/_index.js @@ -1,5 +1,23 @@ var MUB = { _uid : 0 + ,_minRoot : '/min/?' + ,checkRewrite : function () { + var testUri = location.pathname.replace(/\/[^\/]*$/, '/rewriteTest.js').substr(1); + function fail() { + $('#minRewriteFailed')[0].className = 'topNote'; + }; + $.ajax({ + url : '../f=' + testUri + '&' + (new Date()).getTime() + ,success : function (data) { + if (data === '1') { + MUB._minRoot = '/min/'; + $('#minRoot').html('/min/'); + } else + fail(); + } + ,error : fail + }); + } /** * Get markup for new source LI element */ @@ -108,7 +126,7 @@ var MUB = { ++pos; } base = base.replace(/[^\/]+$/, ''); - var uri = '/min/?f=' + sources.join(','); + var uri = MUB._minRoot + 'f=' + sources.join(','); if (base.charAt(base.length - 1) === '/') { // we have a base dir! var basedSources = sources @@ -118,7 +136,7 @@ var MUB = { basedSources[i] = sources[i].substr(base.length); } base = base.substr(0, base.length - 1); - var bUri = '/min/?b=' + base + '&f=' + basedSources.join(','); + var bUri = MUB._minRoot + 'b=' + base + '&f=' + basedSources.join(','); //window.console && console.log([uri, bUri]); uri = uri.length < bUri.length ? uri @@ -178,6 +196,7 @@ var MUB = { * Runs on DOMready */ ,init : function () { + $('#app').show(); $('#sources').html(''); $('#add button').click(MUB.addButtonClick); // make easier to copy text out of @@ -213,8 +232,10 @@ var MUB = { } ,dataType : 'text' }); + $.browser.msie && $('#getBm p:last').append(' Sorry, not supported in MSIE!'); MUB.addButtonClick(); } + MUB.checkRewrite(); } }; window.onload = MUB.init; \ No newline at end of file diff --git a/min/builder/bm.js b/min/builder/bm.js index 56a639f..10d1943 100644 --- a/min/builder/bm.js +++ b/min/builder/bm.js @@ -21,7 +21,11 @@ javascript:(function() { while (o = d.getElementsByTagName('script')[i++]) o.src && !(o.type && /vbs/i.test(o.type)) && add(o.src); i = 0; - while (o = d.styleSheets[i++]) + while (o = d.styleSheets[i++]) + /* http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html#StyleSheets-DocumentStyle-styleSheets + document.styleSheet is a list property where [0] accesses the 1st element and + [outOfRange] returns null. In IE, styleSheets is a function, and also throws an + exception when you check the out of bounds index. (sigh) */ sheet(o); if (uris.length) window.open('%BUILDER_URL%#' + uris.join(',')); diff --git a/min/builder/index.php b/min/builder/index.php index bd5a7b6..f67b4a7 100644 --- a/min/builder/index.php +++ b/min/builder/index.php @@ -9,8 +9,7 @@ if (! $min_enableBuilder) { ob_start(); ?> - + Minify URI Builder @@ -22,23 +21,33 @@ h1 {margin-top:0;} #sources li {margin:0 0 0 40px} #sources li input {margin-left:2px} #add {margin:5px 0 1em 40px} -#update, #results {display:none} +.hide {display:none} #uriTable {border-collapse:collapse;} #uriTable td, #uriTable th {padding-top:10px;} #uriTable th {padding-right:10px;} #groupConfig {font-family:monospace;} b {color:#c00} -#cachePathNote {background: #ff9; display:inline-block; padding:.5em .6em;} +.topNote {background: #ff9; display:inline-block; padding:.5em .6em; margin:0 0 1em;} -

Note: Please set $min_cachePath +

Note: Please set $min_cachePath in /min/config.php to improve performance.

+

Note: Your webserver does not seem to + support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which +may reduce the benefit of proxy cache servers.

+

Minify URI Builder

+ + +
+

Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine and click [Update].

@@ -47,20 +56,21 @@ and click [Update].

-

+

-
+

Minify URI

-

Place this URI in your HTML to serve the files above combined, minified, compressed and with cache headers.

+

Place this URI in your HTML to serve the files above combined, minified, compressed and +with cache headers.

URI/min (opens in new window)
HTML

How to serve these files as a group

-

For the best performance you can serve these files as a pre-defined group with a URI like: -/min/?g=keyName

+

For the best performance you can serve these files as a pre-defined group with a URI +like: /min/?g=keyName

To do this, add a line like this to /min/groupsConfig.php:

return array(
@@ -77,7 +87,7 @@ and click [Update].

on your site. When you active it, this page will open in a new window with a list of available URIs to add.

-

Create Minify URIs (right-click, add to favorites/bookmarks)

+

Create Minify URIs (right-click, add to bookmarks)

Combining CSS files that contain @import

@@ -86,13 +96,19 @@ remove them. Therefore, you will want to remove those that point to files alread in your list, and move any others to the top of the first file in your list (imports below any styles will be ignored by browsers as invalid).

If you desire, you can use Minify URIs in imports and they will not be touched -by Minify. E.g. @import "/min/?g=css2";

+by Minify. E.g. @import "/min/?g=css2";

+ +

-

Need help? Search or post to the Minify discussion list.

-

This app is minified :) view source

+

Need help? Search or post to the Minify discussion list.

+

This app is minified :) view +source

- +