documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Helper that emits a head.js compatible javascript snippet #146

Closed scudco closed 13 years ago

scudco commented 13 years ago

include_headjs_javascripts will emit a script tag that uses head.js to load javascripts.

The headjs_path can be set in the jammit config and defaults to head.min.js (i.e., public/javascripts/head.min.js).

I tested this as best I could and attempted to follow the most of Jammit's conventions.

jashkenas commented 13 years ago

Thanks for the patch -- it's very nice.

But I'm afraid we don't want to have Jammit bless any particular script loader. You should be able to use any of them to require precompiled assets as you see fit.

scudco commented 13 years ago

That makes sense. Do you think there is a middle ground we might find? Before writing this patch I was using Jammit.asset_url and Jammit.packager.individual_urls to build lines of JS.

https://gist.github.com/a6cdd700c55e2c2ccc0c

So that is pretty ugly, but if I could have one method (or maybe there is one and I overlooked it) that returned an array of asset urls in which my code was not the one doing the branching based on Rails.env, then I could simplify the above quite a bit. I'd be happy to refactor, add that kind of method, and add some documentation on how to use headjs with that method if you think it is a good middle ground.

jashkenas commented 13 years ago

One quick thought, before we go down this road... I've always been curious about this.

Do you mind benchmarking load times, in your Jammit'd app, first trying with your current head.js solution, and then trying the same page using Jammit's default include_javascripts helper?

I'd be very interested to know if head.js is helping or hurting load time for you.

scudco commented 13 years ago

Yeah, that's probably a good thing to know ;)

I'll see if I can run some tests today. On Wednesday, March 23, 2011 at 11:18 AM, jashkenas wrote: One quick thought, before we go down this road... I've always been curious about this.

Do you mind benchmarking load times, in your Jammit'd app, first trying with your current head.js solution, and then trying the same page using Jammit's default include_javascripts helper?

I'd be very interested to know if head.js is helping or hurting load time for you.

Reply to this email directly or view it on GitHub: https://github.com/documentcloud/jammit/pull/146#issuecomment-908902