• Resolved timholz

    (@timholz)


    Hi
    Today i deferred jquery and all other scripts. This works well.
    There is one error – jQuery not defined – i receive from the cdata script, which is injected in the head by class-easyfancybox.php. Well, at least i guess, that this is the cause.

    I tried to add defer=”defer” in the <script> tag in class-easyfancybox.php, but the error persisted.

    On another site, where i have the proversion installed, i used the same technique to load all the scripts and the cdata script does not appear in the head.
    Is this due to the pro-version or is there a way to load or defer the cdata script, so it won’t show – jQuery not defined?

    Additional Info (how i deregister and dequeue all source files):

    //remove fancybox style
    add_action('wp_print_styles', 'mytheme_dequeue_css_from_plugins', 100);
    function mytheme_dequeue_css_from_plugins() {
    wp_dequeue_style( 'fancybox' );
    }
    
    	
    add_action('wp_head','my_remove_fancybox_head',999);
    add_action('wp_footer','my_remove_fancybox_footer',999);
    function my_remove_fancybox_head() {
    	wp_deregister_script('jquery-fancybox');
    	wp_deregister_script('jquery-easing');
    	wp_deregister_script('jquery-mousewheel');
    	wp_deregister_script('jquery-metadata');
    	wp_deregister_script( 'jquery-masonry' );
    	wp_dequeue_script('jquery-fancybox');
    	wp_dequeue_script('jquery-fancybox');
    	wp_dequeue_script( 'jquery-masonry' );
        
    }
    function my_remove_fancybox_footer() {
    	wp_dequeue_script('jquery-fancybox');
    	wp_dequeue_script('jquery-easing');
    	wp_dequeue_script('jquery-mousewheel');
    	wp_dequeue_script('jquery-metadata');
    }

    This works well, as long as i do not defer jquery.
    Later on, i add my styles and scripts.

    Any idea how to remove the error when jquery is deferred?
    Thanks
    theo

    • This topic was modified 7 years, 10 months ago by timholz.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Can you share a link?

    On another site, where i have the proversion installed, i used the same technique to load all the scripts and the cdata script does not appear in the head.

    Where does it appear then?

    Thread Starter timholz

    (@timholz)

    Hi
    Yes, here is the link to the site where i get no error: example
    I have found a hack.
    I disable the plugin and just enqueue all the needed scripts, which i extracted from the plugin and then i call the function in my own jquery file:

     //add fancybox class for product images
      $('.my_special_image_class').addClass('fancybox');
    
      /* This is basic - uses default settings */
      
      $("a.fancybox").fancybox({
        'hideOnContentClick': true,
        'showCloseButton' : true,
        'showNavArrows' : false,
        'centerOnScroll' : true,
        'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic',
        'easingIn'  : 'easeOutBack',
        'easingOut' : 'easeInBack',
        'speedIn'   : 300, 
        'speedOut'    : 300, 
        'overlayShow' : true,
        'overlayOpacity' : 0.7
      });

    It works well, but of course lacks the convenience of your plugin.
    But no more errors and a speedy performance.
    Thanks for your interest
    theo

    In any case, there should not be a problem loading jQuery in the footer, as long as it is loaded there before all other jquery dependent script files.

    For example, on https://demo.status301.net/ there is the excellent simple plugin Scripts to Footer activated. It pushes, as it sais, every script file to the footer but (as it cannot touch it) leaves the FancyBox script snippet in the head section. But even when jQuery has not been loaded at that point, there is no problem…

    Note that there is no usage nor need for defer or async. The snippet in the head does not add any significant parsing time as it only defines a few functions. These will be triggered to run after the document has been loaded, in the footer.

    Thread Starter timholz

    (@timholz)

    Ok, thanks, i’ll take a good look at the links you provided.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘script fancybox cdata in head’ is closed to new replies.