thumblemonks / smurf

Rails plugin to automatically minify JavaScript and CSS when their bundles get cached
http://gusg.us/code/ruby/smurf-rails-autominifying-js-css-plugin.html
MIT License
193 stars 12 forks source link

Does this work with <script>...</script>? #13

Open balupton opened 13 years ago

balupton commented 13 years ago

I'm coming from Zend Framework and using the bundlers found here: https://github.com/balupton/balphp/tree/master/lib/Bal/View/Helper

It supports adding script elements to your bundled js file too (so would add script('hello')\n to your bundle file - in order of course).

gus commented 13 years ago

That doesn't currently work because Smurf simply "hijacks" the standard rails behavior for jamming a bunch of resources together. However, that's certainly an interesting feature. On the one hand, I could see people saying "if you need that much inline Javascript, why not just make a library for it" ... and I certainly wouldn't argue with them at a philosophical level.

The impetus behind the resource concatenation built into rails is to reduce the number of network connections a browser needs to make to get your site's library of javascript/css. Smurf takes this best practice and applies the best practice of minification/compression. I'm personally just wondering what moving inline JS into this separate resource gains you. This is not meant to be an argument or a deflection of any mind; I truly would like to know as I have some ideas about how smurf could help make this happen.

balupton commented 13 years ago

:-) nice replies, thanks!

Yeah sure, to answer your question on why this would be important - some scripts, such as Mozilla's SkyWriter/Bespin as well as Aloha Editor require a script elements to be inserted before them which contains the configuration needed to load those scripts correctly. Eg.

<script type="text/javascript">
    var Aloha_Base = '...';
</script>
<script type="text/javascript" src="aloha_editor.js"</script>

Another benefit is that it cleans up your HTML, and minifies those inline scripts as you'd like - bringing requests smaller as well.

What ideas do you have? As I'm completely new to Ruby and Rails - although it's something I'm committed to learning! And coming from a extremely strong PHP + Zend Framework background I have a lot of experience so definitely up for the challenge too!