Re: Comiling CoffeeScript in Production

34 views
Skip to first unread message

Konstantin Haase

unread,
Nov 19, 2012, 12:30:14 PM11/19/12
to sina...@googlegroups.com
We simply use rake-pipeline, which comes with a middleware that recompiles stuff on request in dev mode.

However, if you have a large project, this can significantly slow down request processing, so we moved to just having `rerun rakep` run in parallel.

Konstantin

On Nov 19, 2012, at 5:07 PM, DAZ <daz...@gmail.com> wrote:

Hi,

I've been using the following route handler to compile coffeescript on the fly:

get '/javascripts/application.js' do
  coffee :application
end

But I'd rather not do this in production and would rather compile it locally into a JavaScript file.

The problem I then have is that the compiled JavaScript file gets used in development, rather than the coffeescript file that I'm editing. This is because a static JS file exists, so it gets served, before my route handler picks it up.

The only way I can think of is to use some sort of conditional logic in the layout like this:

<% = coffee :application if development? %>
 <% if production? %>
  <script src="/javascripts/application.js">
<% end %>

Has anybody got any better ways of doing this? 

cheers,

DAZ

--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sinatrarb/-/TdLSJ4yGEykJ.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.

DAZ

unread,
Nov 19, 2012, 2:17:51 PM11/19/12
to sina...@googlegroups.com
Thanks Ben and Konstantin,

I was aware of Sprockets in Rails and have been looking at Rake Pipeline (which looks great).

Konstantine - I wasn't aware that rake-pipeline recompiled on each request (the docs mention needing a rake task to compile). That's awesome for small projects. Not sure what you mean by 'rerun rakep' run in parallel??

cheers,

DAZ

Konstantin Haase

unread,
Nov 19, 2012, 3:34:42 PM11/19/12
to sina...@googlegroups.com
It only recompiles if you use the middleware (which you should not in production) and only if a source file changed.

Konstantin

To view this discussion on the web visit https://groups.google.com/d/msg/sinatrarb/-/Tx2kpKR4-K4J.

DAZ

unread,
Nov 19, 2012, 4:12:25 PM11/19/12
to sina...@googlegroups.com
Just found this that seems to do the job ...


DAZ

Alex Chaffee

unread,
Nov 19, 2012, 5:53:37 PM11/19/12
to sina...@googlegroups.com
rerun is a program that runs a command, then reruns it if any files change.
http://github.com/alexch/rerun
(yes, I wrote it :-))

It's arguably faster than other solutions since it recompiles when the file changes, not when the request is made. But you know, use whatever works for you.

Reply all
Reply to author
Forward
0 new messages