Skip to main content
added 6 characters in body
Source Link
gmazzap
  • 46.3k
  • 6
  • 95
  • 147

I had a hard time finding the correct way to do this. I want to load the CDN resources here: http://www.bootstrapcdn.com/ but use wp_enqueue_scriptswp_enqueue_scripts and have local fall backfallback.

This is the method I am using for local fall back now directly in header.php: window.jQuery || document.write('\x3C/script>')

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.js">\x3C/script>')</script>

I want something like this for all resources but also using wp_enqueue_scripts. I successful switched the enqueue Jquery using this method but this does not provide a fallback: /** Jquery **/ wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js','', 'latest', true ); wp_enqueue_script('jquery','','',true);

/** Jquery **/
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.5./jquery.min.js','', 'latest', true );
wp_enqueue_script('jquery','','',true);

Any help is greatly appreciated!

I had a hard time finding the correct way to do this. I want to load the CDN resources here: http://www.bootstrapcdn.com/ but use wp_enqueue_scripts and have local fall back.

This is the method I am using for local fall back now directly in header.php: window.jQuery || document.write('\x3C/script>')

I want something like this for all resources but also using wp_enqueue_scripts. I successful switched the enqueue Jquery using this method but this does not provide a fallback: /** Jquery **/ wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js','', 'latest', true ); wp_enqueue_script('jquery','','',true);

Any help is greatly appreciated!

I had a hard time finding the correct way to do this. I want to load the CDN resources here: http://www.bootstrapcdn.com/ but use wp_enqueue_scripts and have local fallback.

This is the method I am using for local fall back now directly in header.php:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.js">\x3C/script>')</script>

I want something like this for all resources but also using wp_enqueue_scripts. I successful switched the enqueue Jquery using this method but this does not provide a fallback:

/** Jquery **/
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.5./jquery.min.js','', 'latest', true );
wp_enqueue_script('jquery','','',true);

Any help is greatly appreciated!

Source Link

How do you load js and style resources from CDN with local fallback using wp_enqueue_scripts?

I had a hard time finding the correct way to do this. I want to load the CDN resources here: http://www.bootstrapcdn.com/ but use wp_enqueue_scripts and have local fall back.

This is the method I am using for local fall back now directly in header.php: window.jQuery || document.write('\x3C/script>')

I want something like this for all resources but also using wp_enqueue_scripts. I successful switched the enqueue Jquery using this method but this does not provide a fallback: /** Jquery **/ wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js','', 'latest', true ); wp_enqueue_script('jquery','','',true);

Any help is greatly appreciated!