Conditional javascript required in asset pipeline

I am struggling with an asset pipeline. I download dojo from the Google CDN by putting this in my template:

= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js', :'data-dojo-config' => %Q(dojoBlankHtmlUrl:'/blank.html', baseUrl: 'assets/', modulePaths: {custom: 'javascripts/modules'})

I just want the local version to be backed up locally, or if the CDN is down. I thought about it:

script typeof(dojo) === "undefined" && document.write(unescape('%3Cscript src="js/libs/dojo-1.6.1.min.js"%3E%3C/script%3E'));

But I don’t like it, because it works from the asset pipeline. I want to keep dojo in vendors/assets/javascripts/dojo. How can I get a backup for asset pipeline maintenance.

Is there a way to declare a conditional requirement in an asset pipeline. I want to run some javascript tests and depending on the result serve as a file.

thank

+2
source share
2 answers

Thanks Richard!

, yepnope . . , , ( ):


1/ //javascripts/ dojo.js.

2/ config/application.rb:

# Precompile these assets files
config.assets.precompile += ['dojo.js']

3/ :

= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/dojo/#{Settings.dojoVersion}/dojo/dojo.xd.js", :'data-dojo-config' => %Q(dojoBlankHtmlUrl:'/blank.html', baseUrl: 'assets/', modulePaths: {custom: 'javascripts/modules'})
script = "typeof(dojo) === \"undefined\" && document.write(unescape('%3Cscript src=\"#{asset_path('dojo')}\"%3E%3C/script%3E'));".html_safe

Rails Google javascript_include_tag,: test : local, . .

+1

yepnope, ( ), . :


yepnope([{
  load: 'http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js',
  complete: function () {
    if (!window.jQuery) {
      yepnope('asset_path('you_local_copy_of_dojo') ');
    }
  }
}])

(: erb resource_path)

dojo assets/javascript, . dojo :

config.assets.precompile += 'your_local_file.js'

resource_path.

+2

All Articles