• Resolved zacharyj0198

    (@zacharyj0198)


    Currently, the JS/CSS files for dearflip are loaded on pages that do not need them. This is because wp_enqueue_script and wp_enqueue_style are run upon initialization, when they should be run upon shortcode usage. Requesting that a change be made in future versions of dflip and dflip pro that only enqueues scripts and styles when they are actually needed.

    I can provide a diff file to the dflip team that makes this change.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author DearHive

    (@dearhive)

    Hi,

    We had encountered such request before, but this can be problematic in scenarios where the content is loaded by Ajax and then the flipbooks wont work.

    Best regards,

    DearHive

    @dearhive I understand that this could lead to problems with AJAX implementations. But not providing a solution is a reason for us to not use the DearFlip plugin at all. Performance is very important.

    What if you added a setting where we can set how the assets are included? The setting could come with the following options:

    • Load assets on every page load (optimal for AJAX implementations)
    • Load assets only when the dflip shortcode is used

    The way we work around this at the moment is to dequeue the assets and enqueue them only when the dflip shortcode is used. It works, but is not a future-proof method in case the included script or style names are updated.

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_script( 'dflip-script' );
        wp_dequeue_style( 'dflip-icons-style' );
        wp_dequeue_style( 'dflip-style' );
    }, 11 );
    
    add_filter( 'do_shortcode_tag', function( $output, $tag ) {
        if ( $tag !== 'dflip' ) {
            return $output;
        }
    
        wp_enqueue_script( 'dflip-script' );
        wp_enqueue_style( 'dflip-icons-style' );
        wp_enqueue_style( 'dflip-style' );
    
        return $output;
    }, 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘JS/CSS files for deaflip plugin are loaded when not needed.’ is closed to new replies.