Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

samfoo
Copy link

@samfoo samfoo commented Aug 27, 2012

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.

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.
@travisbot
Copy link

This pull request passes (merged d695e15 into c41186a).

@joliss
Copy link
Member

joliss commented Aug 27, 2012

Thanks for the pull request! I think it's important that the dependencies are declared, so I want to keep the require jquery line, but check issues #15 and #16 for a solution for your problem.

Hm, I should probably add a note about this to the README, this seems to come up a lot.

@joliss joliss closed this Aug 27, 2012
@samfoo
Copy link
Author

samfoo commented Aug 27, 2012

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.

@joliss
Copy link
Member

joliss commented Aug 27, 2012

trying to handle project level dependencies through a gem leads to head-on-table-bangingly frustrating bugs.

I'm pretty set on keeping the require jquery (some rationale to come in a FAQ entry in the README), but could you elaborate on what caused the head-on-table banging for you?

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.

@samfoo
Copy link
Author

samfoo commented Aug 27, 2012

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:

trying to handle project level dependencies through a gem leads to head-on-table-bangingly frustrating bugs.

I'm pretty set on keeping the require jquery (some rationale to come in a FAQ entry in the README), but could you elaborate on what caused the head-on-table banging for you?

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.


Reply to this email directly or view it on GitHub.

@samfoo
Copy link
Author

samfoo commented Aug 27, 2012

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.

@jfirebaugh
Copy link

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.

@gkop
Copy link

gkop commented Oct 25, 2012

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.

@joliss
Copy link
Member

joliss commented Oct 25, 2012

On Thu, Oct 25, 2012 at 1:22 AM, John Firebaugh
notifications@github.com wrote:

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.

Okay, I'm convinced. I'll accept a pull request to remove the //= require jquery. I think we'll just bump the major version and make a
new release. Please don't forget to update the History and put an
upgrade note in the README.

@semaperepelitsa
Copy link

Did you see "stubbing" feature of sprockets? sstephenson/sprockets#254

@jfirebaugh
Copy link

Yes. It only recently became available in Rails however: 3.2.9 is the first release that has a sprockets dependency >= 2.2.0.

@joliss
Copy link
Member

joliss commented Dec 26, 2012

This has been open for a while, so I'm closing it. If anybody wants to update Rakefile to not include require jquery, I'll accept a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants