mirror of
https://github.com/mrclay/minify.git
synced 2025-08-13 17:44:00 +02:00
mod_rewrite allows Minify URIs w/o "?"
builder/_index.js checks for this feature
This commit is contained in:
2
min/.htaccess
Normal file
2
min/.htaccess
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
RewriteEngine on
|
||||||
|
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
|
@@ -1,5 +1,23 @@
|
|||||||
var MUB = {
|
var MUB = {
|
||||||
_uid : 0
|
_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
|
* Get markup for new source LI element
|
||||||
*/
|
*/
|
||||||
@@ -108,7 +126,7 @@ var MUB = {
|
|||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
base = base.replace(/[^\/]+$/, '');
|
base = base.replace(/[^\/]+$/, '');
|
||||||
var uri = '/min/?f=' + sources.join(',');
|
var uri = MUB._minRoot + 'f=' + sources.join(',');
|
||||||
if (base.charAt(base.length - 1) === '/') {
|
if (base.charAt(base.length - 1) === '/') {
|
||||||
// we have a base dir!
|
// we have a base dir!
|
||||||
var basedSources = sources
|
var basedSources = sources
|
||||||
@@ -118,7 +136,7 @@ var MUB = {
|
|||||||
basedSources[i] = sources[i].substr(base.length);
|
basedSources[i] = sources[i].substr(base.length);
|
||||||
}
|
}
|
||||||
base = base.substr(0, base.length - 1);
|
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]);
|
//window.console && console.log([uri, bUri]);
|
||||||
uri = uri.length < bUri.length
|
uri = uri.length < bUri.length
|
||||||
? uri
|
? uri
|
||||||
@@ -178,6 +196,7 @@ var MUB = {
|
|||||||
* Runs on DOMready
|
* Runs on DOMready
|
||||||
*/
|
*/
|
||||||
,init : function () {
|
,init : function () {
|
||||||
|
$('#app').show();
|
||||||
$('#sources').html('');
|
$('#sources').html('');
|
||||||
$('#add button').click(MUB.addButtonClick);
|
$('#add button').click(MUB.addButtonClick);
|
||||||
// make easier to copy text out of
|
// make easier to copy text out of
|
||||||
@@ -213,8 +232,10 @@ var MUB = {
|
|||||||
}
|
}
|
||||||
,dataType : 'text'
|
,dataType : 'text'
|
||||||
});
|
});
|
||||||
|
$.browser.msie && $('#getBm p:last').append(' Sorry, not supported in MSIE!');
|
||||||
MUB.addButtonClick();
|
MUB.addButtonClick();
|
||||||
}
|
}
|
||||||
|
MUB.checkRewrite();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
window.onload = MUB.init;
|
window.onload = MUB.init;
|
@@ -21,7 +21,11 @@ javascript:(function() {
|
|||||||
while (o = d.getElementsByTagName('script')[i++])
|
while (o = d.getElementsByTagName('script')[i++])
|
||||||
o.src && !(o.type && /vbs/i.test(o.type)) && add(o.src);
|
o.src && !(o.type && /vbs/i.test(o.type)) && add(o.src);
|
||||||
i = 0;
|
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);
|
sheet(o);
|
||||||
if (uris.length)
|
if (uris.length)
|
||||||
window.open('%BUILDER_URL%#' + uris.join(','));
|
window.open('%BUILDER_URL%#' + uris.join(','));
|
||||||
|
@@ -9,8 +9,7 @@ if (! $min_enableBuilder) {
|
|||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
"http://www.w3.org/TR/html4/strict.dtd">
|
|
||||||
<head>
|
<head>
|
||||||
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
|
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
|
||||||
<title>Minify URI Builder</title>
|
<title>Minify URI Builder</title>
|
||||||
@@ -22,23 +21,33 @@ h1 {margin-top:0;}
|
|||||||
#sources li {margin:0 0 0 40px}
|
#sources li {margin:0 0 0 40px}
|
||||||
#sources li input {margin-left:2px}
|
#sources li input {margin-left:2px}
|
||||||
#add {margin:5px 0 1em 40px}
|
#add {margin:5px 0 1em 40px}
|
||||||
#update, #results {display:none}
|
.hide {display:none}
|
||||||
#uriTable {border-collapse:collapse;}
|
#uriTable {border-collapse:collapse;}
|
||||||
#uriTable td, #uriTable th {padding-top:10px;}
|
#uriTable td, #uriTable th {padding-top:10px;}
|
||||||
#uriTable th {padding-right:10px;}
|
#uriTable th {padding-right:10px;}
|
||||||
#groupConfig {font-family:monospace;}
|
#groupConfig {font-family:monospace;}
|
||||||
b {color:#c00}
|
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;}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<?php if (! isset($min_cachePath)): ?>
|
<?php if (! isset($min_cachePath)): ?>
|
||||||
<p id=cachePathNote><strong>Note:</strong> Please set <code>$min_cachePath</code>
|
<p class=topNote><strong>Note:</strong> Please set <code>$min_cachePath</code>
|
||||||
in /min/config.php to improve performance.</p>
|
in /min/config.php to improve performance.</p>
|
||||||
<?php endIf; ?>
|
<?php endIf; ?>
|
||||||
|
|
||||||
|
<p id=minRewriteFailed class="hide"><strong>Note:</strong> Your webserver does not seem to
|
||||||
|
support mod_rewrite (used in /min/.htaccess). Your Minify URIs will contain "?", which
|
||||||
|
<a href="http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/"
|
||||||
|
>may reduce the benefit of proxy cache servers</a>.</p>
|
||||||
|
|
||||||
<h1>Minify URI Builder</h1>
|
<h1>Minify URI Builder</h1>
|
||||||
|
|
||||||
|
<noscript><p class="topNote">Javascript and a browser supported by jQuery 1.2.6 is required
|
||||||
|
for this application.</p></noscript>
|
||||||
|
|
||||||
|
<div id=app class=hide>
|
||||||
|
|
||||||
<p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
|
<p>Create a list of Javascript or CSS files (or 1 is fine) you'd like to combine
|
||||||
and click [Update].</p>
|
and click [Update].</p>
|
||||||
|
|
||||||
@@ -47,20 +56,21 @@ and click [Update].</p>
|
|||||||
|
|
||||||
<div id=bmUris></div>
|
<div id=bmUris></div>
|
||||||
|
|
||||||
<p><button id=update>Update</button></p>
|
<p><button id=update class=hide>Update</button></p>
|
||||||
|
|
||||||
<div id=results>
|
<div id=results class=hide>
|
||||||
|
|
||||||
<h2>Minify URI</h2>
|
<h2>Minify URI</h2>
|
||||||
<p>Place this URI in your HTML to serve the files above combined, minified, compressed and with cache headers.</p>
|
<p>Place this URI in your HTML to serve the files above combined, minified, compressed and
|
||||||
|
with cache headers.</p>
|
||||||
<table id=uriTable>
|
<table id=uriTable>
|
||||||
<tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
|
<tr><th>URI</th><td><a id=uriA class=ext>/min</a> <small>(opens in new window)</small></td></tr>
|
||||||
<tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
|
<tr><th>HTML</th><td><input id=uriHtml type=text size=100 readonly></td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>How to serve these files as a group</h2>
|
<h2>How to serve these files as a group</h2>
|
||||||
<p>For the best performance you can serve these files as a pre-defined group with a URI like:
|
<p>For the best performance you can serve these files as a pre-defined group with a URI
|
||||||
<code>/min/?g=keyName</code></p>
|
like: <code>/min/?g=keyName</code></p>
|
||||||
<p>To do this, add a line like this to /min/groupsConfig.php:</p>
|
<p>To do this, add a line like this to /min/groupsConfig.php:</p>
|
||||||
|
|
||||||
<pre><code>return array(
|
<pre><code>return array(
|
||||||
@@ -77,7 +87,7 @@ and click [Update].</p>
|
|||||||
on your site. When you active it, this page will open in a new window with a list of
|
on your site. When you active it, this page will open in a new window with a list of
|
||||||
available URIs to add.</p>
|
available URIs to add.</p>
|
||||||
|
|
||||||
<p><a id=bm>Create Minify URIs</a> <small>(right-click, add to favorites/bookmarks)</small></p>
|
<p><a id=bm>Create Minify URIs</a> <small>(right-click, add to bookmarks)</small></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>Combining CSS files that contain <code>@import</code></h3>
|
<h3>Combining CSS files that contain <code>@import</code></h3>
|
||||||
@@ -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
|
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).</p>
|
(imports below any styles will be ignored by browsers as invalid).</p>
|
||||||
<p>If you desire, you can use Minify URIs in imports and they will not be touched
|
<p>If you desire, you can use Minify URIs in imports and they will not be touched
|
||||||
by Minify. E.g. <code>@import "/min/?g=css2";</code></p>
|
by Minify. E.g. <code>@import "<span id=minRoot>/min/?</span>g=css2";</code></p>
|
||||||
|
|
||||||
|
</div><!-- #app -->
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<p>Need help? Search or post to the <a class=ext href="http://groups.google.com/group/minify">Minify discussion list</a>.</p>
|
<p>Need help? Search or post to the <a class=ext
|
||||||
<p><small>This app is minified :) <a class=ext href="http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php">view source</a></small></p>
|
href="http://groups.google.com/group/minify">Minify discussion list</a>.</p>
|
||||||
|
<p><small>This app is minified :) <a class=ext
|
||||||
|
href="http://code.google.com/p/minify/source/browse/trunk/min/builder/index.php">view
|
||||||
|
source</a></small></p>
|
||||||
|
|
||||||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
|
<script type="text/javascript"
|
||||||
|
src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// workaround required to test when /min isn't child of web root
|
// workaround required to test when /min isn't child of web root
|
||||||
|
1
min/builder/rewriteTest.js
Normal file
1
min/builder/rewriteTest.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
1
|
Reference in New Issue
Block a user