-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't force loading jquery through the asset pipeline #17
Conversation
For our (and probably many) use cases, I want to load jquery from the google/ms/jquery CDN in production. By requiring jquery in jquery.ui.core, it was forcing all of jquery into the asset pipeline in all cases, even if not necessary.
Stubbing the directive strikes me as being quite hacky. It seems to me that a dependency of jquery for jquery-ui is fairly obvious. Even when custom building jquery-ui custom js files from jqueryui.com they don't bundle jquery along with them (as an example). Dependency management within the project makes sense to me, but trying to handle project level dependencies through a gem leads to head-on-table-bangingly frustrating bugs. |
I'm pretty set on keeping the The problem and solution both seem fairly obvious to me, so perhaps I'm missing something. I'd be interested what kind of gotchas and usability issues people encounter. |
The problem being obvious is only true in the case that you're the author of the gem, and it certainly breaks with other rails-js gem patterns. Take the most trivial case: if Rails.production?
# load from Cdn
else
# load locally
# javascript_include_tag 'application' Now if I include jquery ui components anywhere after this -- which would be normal for projects using sprockets -- everything will appear fine both locally and on production, but several hundred kbs will have been added to my compile file and would be non obvious simply by looking at the compiled minified version. This is likely a bug that many people using rails_jquery_ui are experiencing without even realizing it. Or take my case: experiencing a bug in jquery and needing to use a custom or edge release in some situations. Yes, the problem is clear when you remember that you have the dependency in a gem that you would expect to simply be simply loading js. I understand the desire to manage dependencies, but binding to rails_jquery only limits flexibility and results in non obvious problems. Project level dependencies make sense to leave in the hands of project developers. Gem level dependencies should be abstracting in the gem. It makes life easier for everyone. Ultimately it's not a big deal, I'll just roll my own jquery ui js and serve that, but I think you're limiting the usefulness of the project by forcing it. Sent from my phone, excuse the brevity On 27/08/2012, at 19:19, Jo Liss notifications@github.com wrote:
|
Ultimately I think the point is: There isn't really a dependency on "jquery" anyway (at least not in the rails_jquery gem sense). The dependency is that jquery is loaded somewhere in my page. It really shouldn't by this gems responsibility to decide how that happens. |
I've got to agree with @samfoo on this as I'm facing a similar problem. Parts of my application depend on jQuery 1.4.x and parts on 1.8.x, so I have separate jquery-1.4.js and jquery-1.8.js assets requires as appropriate. I can't use jquery-ui-rails with this project unless I either fork it and remove the jquery require as suggested in the pull request, or run edge rails or a forked rails that updates the sprockets dependency to a version that supports the stub directive. The version of sprockets that Rails 3.1 and 3.2 depend on don't support it. |
I'm facing a similar problem, trying to load some jquery-ui modules on some pages and some jquery-ui modules on other pages, with all pages sharing a common application.js file that includes jquery. I am using @samfoo's fork in order to avoid pulling in extra jqueries when I pull in my jquery-ui modules. I'd be glad to try stubbed dependencies but they're not available yet in Rails 3.2.x. |
On Thu, Oct 25, 2012 at 1:22 AM, John Firebaugh
Okay, I'm convinced. I'll accept a pull request to remove the |
Did you see "stubbing" feature of sprockets? sstephenson/sprockets#254 |
Yes. It only recently became available in Rails however: 3.2.9 is the first release that has a sprockets dependency >= 2.2.0. |
This has been open for a while, so I'm closing it. If anybody wants to update |
For our (and probably many) use cases, I want to load jquery from the google/ms/jquery CDN in a production environment.
By requiring jquery in jquery.ui.core, it was forcing all of jquery into the asset pipeline in all cases, even if not necessary.