Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use Google's CDN to host jQuery #61

Closed
ndbroadbent opened this Issue July 11, 2012 · 13 comments

9 participants

Nathan Broadbent Jarin Udom Kenn Ejima André Arko benatkin Mario Visic Johannes Barre Brian Armstrong Peter Sugihara
Nathan Broadbent

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.)
Jarin Udom

+1

Kenn Ejima
kenn commented July 11, 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?

André Arko
Collaborator

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?

Nathan Broadbent

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.

André Arko
Collaborator
benatkin

-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.

Nathan Broadbent

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 :)

Nathan Broadbent ndbroadbent closed this July 14, 2012
Mario Visic

-1

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

Johannes Barre
iGEL commented July 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.

Brian Armstrong

+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

Jarin Udom

@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.

André Arko
Collaborator

@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
Something went wrong with that request. Please try again.