I have a jQuery script that I added an ASYNC attribute to. It seems to work OK in Firefox, but intermittently fails in Chrome and IE.
The PHP for loading adding the async attrib. This works fine:
function add_async_attribute($tag, $handle) {
if ( substr($handle,0,3) !== 'jch' )
return $tag;
return str_replace( ' src', ' async="async" src', $tag );
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
The JS file that causes a problem with the ASYNC attrib:
jQuery(document).ready(function($) {
jQuery('.home #intro_reel').jchTextReel( {fadeTime: 16000} );
});
jQuery.fn.extend({
jchTextReel: function(options) {
var defaults = {
fadeTime: 10000,
mouseOverColor : '#000000',
mouseOutColor : '#ffffff'
}
var options = jQuery.extend(defaults, options);
return this.each(function() {
var o = options;
....etc....
Chrome shows an error 'jchTextReel is not a function'.
Again, removing the ASYNC attrib makes the script work OK again. OR, if I hit F5 to reload, the script seems to work.
Why? How do I fix?