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

Use Google's CDN to host jQuery #61

Closed
ndbroadbent opened this issue Jul 12, 2012 · 13 comments
Closed

Use Google's CDN to host jQuery #61

ndbroadbent opened this issue Jul 12, 2012 · 13 comments

Comments

@ndbroadbent
Copy link

Here's a gem that already provides this behaviour: https://github.com/kenn/jquery-rails-cdn

I think this should be the default behaviour of the jquery-rails gem.
It seems like a waste of resources if we are all compiling our own copies of jQuery and jquery-ui into our application.js.

Sites like Twitter, Stack Overflow, Posterous, and Foursquare are ensuring that your users will already have a cached copy of jQuery ready for you to use, because they all reference Google's CDN. This provides cross-site caching.

You may find it helpful to read the following articles:

In order to implement this, we would need to provide an install generator (rails g jquery:install), since we'll need to make some changes to the Rails application:

  • Remove //= require jquery from application.js
  • Add = jquery_include_tag :google_schemeless to your layout
  • Add config.assets.precompile += ['jquery.js'] to application.rb (provides a fallback in case Google's CDN goes down, is blocked, you're offline, etc.)
@jarinudom
Copy link

+1

@kenn
Copy link
Contributor

kenn commented Jul 12, 2012

I agree that CDN support would be great if it's included in jquery-rails, but I also think jquery_include_tag sounds a bit too ugly to be the default to my taste.

To become as a default in Rails, better abstraction (no inclusion of jquery_ prefix) is needed IMO. cdn_ prefix, maybe?

@indirect
Copy link
Member

Sooo... maybe I'm not getting something, but since there's already a gem that does this, why is it valuable to include this in jquery-rails?

@ndbroadbent
Copy link
Author

I personally think it would be a good default. If a large majority of Rails apps are using jquery-rails, then I think they could all be using the jQuery hosted on Google's CDN.

Most developers won't care about this enough to do anything, so in order for the CDN idea to get any traction, it needs to be adopted by the gem they already use.

@indirect
Copy link
Member

But you just said that the CDN version would have to be installed by a generator. That means that developers would have to care enough about this to do something, which you just said they won't do. How is this worthwhile either way? If developers do care, they can add the CDN version by adding four characters to their Gemfile, and if they don't care, adding a generator to this gem won't help them anyway.

On Jul 11, 2012, at 10:46 PM, Nathan Broadbentreply@reply.github.com wrote:

I personally think it would be a good default. If a large majority of Rails apps are using jquery-rails, then I think they could all be using the jQuery hosted on Google's CDN.

Most developers won't care about this enough to do anything, so in order for the CDN idea to get any traction, it needs to be adopted by the gem they already use.


Reply to this email directly or view it on GitHub:
#61 (comment)

@benatkin
Copy link

-1 this isn't appropriate for Ruby on Rails which takes Open Source very seriously. A rails app by default shouldn't rely on proprietary infrastructure. Also google gets ip addresses and referrers which can be logged when someone visits a site that has CDN jQuery and doesn't have it cached.

@ndbroadbent
Copy link
Author

OK, I agree that the Open Source / proprietary infrustructure part makes some sense.
I am of the opinion that fetching jQuery from the Google CDN isn't a huge privacy risk, but the fact that it has been mentioned multiple times is enough to convince me that this idea isn't going to happen any time soon.

It's a shame though, since Google's CDNs does provide a great service with the best intentions, and it would become even more effective if more websites started using it.

Oh well, thanks for everyone's input. I will close this issue for now :)

@mariovisic
Copy link

-1

This would mean having a separate request for jquery.
For anyone already using a CDN this could hurt performance.

@iGEL
Copy link

iGEL commented Jul 16, 2012

@mariovisic It will only hurt the performance, if the specific version is not already in the browser cache. In most cases, it will, since many sites use Google's CDN. The widely used HTML5Boilerplate also uses Google's CDN for jQuery.

@ndbroadbent If there is any interest, I would develop a patch, which provides the functionality as an option, not enabled by default.

@barmstrong
Copy link

+1 by making this a default in rails it would help grow the base of sites out there, and increase the likelihood of any given browser having it cached

@jarinudom
Copy link

@ndbroadbent Exactly, if it's a default, most people will not change it without a good reason and everyone benefits. Anyone who wants to change it for a good reason (or a bad reason) is perfectly entitled to.

@psugihara
Copy link

+1

@indirect
Copy link
Member

@ptrsghr, this isn't going to be added to jquery-rails. If you want your Rails site to serve jQuery from a CDN, use the "jquery-rails-cdn" gem instead.

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

No branches or pull requests

9 participants