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

Compile to tmp/javascripts instead of public/javascripts #12

Open mrrooijen opened 13 years ago

mrrooijen commented 13 years ago

Hey, I'm deploying an app to Heroku and was wondering if it's possible to compile javascripts such as:

= javascript_include_tag 'jquery.min', 'rails', 'application', :cache => true

in to Rails.root/tmp/javascripts rather than Rails.root/public/javascripts since that's the only writable directory on Heroku. It's not possible to do the following:

= javascript_include_tag 'jquery.min', 'rails', 'application', :cache => "#{Rails.root}/tmp/javascripts/all.js"

Any idea's how I can accomplish this?

Thanks!

peppyheppy commented 13 years ago

Hi meskyanichi,

This is something that I ran into when using heroku as well. Even if you could write the javascripts and css to the /tmp directory, could you access them in a web browser? I would be open to other ideas if you have them. The best solution would be the following: https://github.com/thumblemonks/smurf/issues/closed#issue/8

Hope this helps.

mrrooijen commented 13 years ago

Yeah. People that use Compass/SASS to compile Stylesheets on Heroku also compile it to Heroku and tell Rack to look in the tmp dir for the stylesheets.

Check this out: https://gist.github.com/716284

It's a Gist for Compass/Stylesheets compiled to the tmp/stylesheets/compiled dir and serve them from there as if they were in the public/stylesheets/compiled directory.

I am quite sure that if you'd compress your javascripts to tmp/javascripts you could do this in your Rails.root/config.ru.

use Rack::Static, :urls => ["/javascripts"], :root => "tmp"

Which would read them from tmp/javascripts.

Only thing is that I don't know how to compile Javascripts with Smurf to a location out side of the Rails.root/public directory.

mrrooijen commented 13 years ago

Let me just add:

Basically what needs to happen is this:

app/views/layouts/application.html.erb <%= javascript_include_tag "jquery", "rails", "application", :cache => true %>

The above could should compile the all.js file to tmp/javascripts/all.js. Then in the browser's source you would see something like:

<script src="/javascripts/all.js"></script>

Then adding this in the Rails.root/config.ru

use Rack::Static, :urls => ["/javascripts"], :root => "tmp"

It should find the tmp/all.js and load it if I am correct.

gus commented 13 years ago

@peppyheppy - Thanks for replying.

@meskyanichi - Do you need any more help with this?

mrrooijen commented 13 years ago

Yeah I actually never figured it out. As mentioned above it should be possible to read out the javascript files from the tmp/ dir like you would with css (when using sass) and deploying to heroku.

I believe that if Smurf could compress/merge all the JS files in to the /tmp dir (optionally) then people could benefit a lot from that when deploying to heroku. I assume it currently isn't possible to do this, but are there any plans to allow the compressed JS files to be created in the tmp/javascripts dir for example? (outside of the public dir)

gus commented 13 years ago

Howdy,

If you can put together any sort of pull-request or even just gist I think that would help a lot in making this a reality. As I stated in another feature request, I haven't needed to have a lot of intimate time with smurf lately and I get a bit disconnected from making improvements to it. Any "physical" research you can do into this would help tremendously.

Is that fair?

Cheers, Gus