Skip to content

Expose version number for bundled jquery.js, for easy use of a CDN#1

Merged
indirect merged 1 commit intorails:masterfrom
purcell:master
Jun 1, 2011
Merged

Expose version number for bundled jquery.js, for easy use of a CDN#1
indirect merged 1 commit intorails:masterfrom
purcell:master

Conversation

@purcell
Copy link
Contributor

@purcell purcell commented May 31, 2011

On production sites, it's nice to use an offsite CDN to serve
jquery.js, and there's a nice technique for seamlessly falling back to
the local bundled jquery.js if the CDN is unavailable:

http://weblogs.asp.net/jgalloway/archive/2010/01/21/using-cdn-hosted-jquery-with-a-local-fall-back-copy.aspx.

To ensure that the CDN jquery.js version matches that bundled with
jquery-rails, it's necessary to programatically access the bundled
version number. This commit allows users to do the following, by
ensuring that the jquery version is no longer hidden away in the
install generator:

= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/#{Jquery::Rails::JQUERY_VERSION}/jquery.min.js"
:javascript
  if (typeof jQuery == 'undefined') {
    document.write(unescape(#{URI.escape(javascript_include_tag('jquery')).to_json}));
  }

…sible place.

On production sites, it's nice to use an offsite CDN to serve
jquery.js, and there's a nice technique for seamlessly falling back to
the local bundled jquery.js if the CDN is unavailable:

http://weblogs.asp.net/jgalloway/archive/2010/01/21/using-cdn-hosted-jquery-with-a-local-fall-back-copy.aspx.

To ensure that the CDN jquery.js version matches that bundled with
jquery-rails, it's necessary to programatically access the bundled
version number. This commit allows users to do the following, by
ensuring that the jquery version is no longer hidden away in the
install generator:

    = javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/#{Jquery::Rails::JQUERY_VERSION}/jquery.min.js"
    :javascript
      if (typeof jQuery == 'undefined') {
        document.write(unescape(#{URI.escape(javascript_include_tag('jquery')).to_json}));
      }
@indirect
Copy link
Member

indirect commented Jun 1, 2011

Looks good, thanks!

indirect pushed a commit that referenced this pull request Jun 1, 2011
Expose version number for bundled jquery.js, for easy use of a CDN
@indirect indirect merged commit db1ea81 into rails:master Jun 1, 2011
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.

2 participants