Minify all JS and CSS via middleware. This means JS or CSS anywhere in the site is minified, not just in the Sprockets-controlled directories. I've also added inline CSS compression, and handling of several common "guards" that get wrapped around JS. Also, leave alone non-JS script tags (which may contain something like jQuery templates). Sprockets no longer has anything to do with minification after this.

This commit is contained in:
Ben Hollis 2012-04-07 20:00:24 -07:00
parent b1ba94cf22
commit 192047d242
16 changed files with 347 additions and 80 deletions

View file

@ -8,24 +8,106 @@ Feature: Minify Javascript
Given "minify_javascript" feature is "disabled"
And the Server is running at "minify-js-app"
When I go to "/inline-js.html"
Then I should see "10" lines
Then I should see:
"""
<script type='text/javascript'>
//<![CDATA[
;(function() {
this;
should();
all.be();
on = { one: line };
})();
//]]>
</script>
<script>
;(function() {
this;
should();
too();
})();
</script>
<script type='text/javascript'>
//<!--
;(function() {
one;
line();
here();
})();
//-->
</script>
<script type='text/html'>
I'm a jQuery {{template}}.
</script>
"""
Scenario: Rendering inline js with a passthrough minifier
Given the Server is running at "passthrough-app"
When I go to "/inline-js.html"
Then I should see "11" lines
Then I should see:
"""
<script type='text/javascript'>
//<![CDATA[
;(function() {
this;
should();
all.be();
on = { one: line };
})();
//]]>
</script>
<script>
;(function() {
this;
should();
too();
})();
</script>
<script type='text/javascript'>
//<!--
;(function() {
one;
line();
here();
})();
//-->
</script>
<script type='text/html'>
I'm a jQuery {{template}}.
</script>
"""
Scenario: Rendering inline js with the feature enabled
Given "minify_javascript" feature is "enabled"
And the Server is running at "minify-js-app"
When I go to "/inline-js.html"
Then I should see "5" lines
Then I should see:
"""
<script type='text/javascript'>
//<![CDATA[
(function(){this,should(),all.be(),on={one:line}})();
//]]>
</script>
<script>
(function(){this,should(),too()})();
</script>
<script type='text/javascript'>
//<!--
(function(){one,line(),here()})();
//-->
</script>
<script type='text/html'>
I'm a jQuery {{template}}.
</script>
"""
Scenario: Rendering external js with the feature enabled
Given "minify_javascript" feature is "enabled"
And the Server is running at "minify-js-app"
When I go to "/javascripts/js_test.js"
Then I should see "1" lines
When I go to "/more-js/other.js"
Then I should see "1" lines
Scenario: Rendering external js with a passthrough minifier
And the Server is running at "passthrough-app"
@ -36,7 +118,7 @@ Feature: Minify Javascript
Given "minify_javascript" feature is "enabled"
And the Server is running at "minify-js-app"
When I go to "/inline-coffeescript.html"
Then I should see "5" lines
Then I should see "6" lines
Scenario: Rendering external js (coffeescript) with the feature enabled
Given "minify_javascript" feature is "enabled"
@ -47,9 +129,10 @@ Feature: Minify Javascript
Scenario: Rendering inline js (coffeescript) with a passthrough minifier
Given the Server is running at "passthrough-app"
When I go to "/inline-coffeescript.html"
Then I should see "17" lines
Then I should see "16" lines
Scenario: Rendering external js (coffeescript) with a passthrough minifier
And the Server is running at "passthrough-app"
When I go to "/javascripts/coffee_test.js"
Then I should see "11" lines
Then I should see "11" lines