Up to 50 percent off

Loading of scripts

This topic contains 5 reply and 5 voices, and was last updated by Chris Swede 10 years, 4 months ago
Viewing 5 Posts - 1 through 5 (of 5 total)
Author Posts
April 14, 2014 at 2:27 pm 18737
Chris Swede Hi, currently WPUF is loading all Javascript and CSS files on all WordPress pages. Is that really necessary? Why not loading it only when a shortcode is included in the current page as you do it with the plugin scripts? There was also a forum post about it one year ago in the WordPress forum: http://wordpress.org/support/topic/plugin-wp-user-frontend-wpuf-breaks-the-themes-layout Regards Jonas
April 14, 2014 at 5:42 pm 18749
Mahi Mahi

Hello,

Its been fixed long time back. Check WPUF -> Settings ->Load Scripts

you can turn if off here.

April 14, 2014 at 5:52 pm 18750
Jonas Jonas

Hello,

as far as I can see in the code (version 2.1.9) it was only changed for the plugin scripts, but not for the scripts of wpuf itself. The Google Maps API, frontend-forms.css and frontend-form.js are still loaded on every WordPress page independent of the “Load Scripts” option.

    function enqueue_scripts() {
        
        $path = plugins_url( '', __FILE__ );
        $scheme = is_ssl() ? 'https' : 'http';
        
<strong>        wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?sensor=true' );
        wp_enqueue_style( 'wpuf-css', $path . '/css/frontend-forms.css' );
        wp_enqueue_script( 'wpuf-form', $path . '/js/frontend-form.js', array('jquery') );</strong>
        
        if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on') == 'on') {
            $this->plugin_scripts();
        } else if ( wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) ) {
            $this->plugin_scripts();
        }
    }

Regards
Jonas

July 10, 2014 at 4:20 pm 23291
Daniel Daniel

I agree with this – google maps scripts are loaded on every page.
I see no point in this, as it should only be loaded if required. Right now it slows down my page with several seconds.

Why are they not loaded inside the if-statement that controls the plugin scripts?

July 13, 2014 at 4:46 pm 23472
Sekander Badsha Sekander Badsha

Mahi have said the fix above. You can control from settings whether to load the scripts in every page or not. Please see the comment above.

July 21, 2014 at 4:16 pm 23871
Chris Swede Chris Swede

Hi, please put this in your theme’s functions.php

function disable_wpuf_scripts() {
    // Remove scripts from all pages except where needed - match IDs to WPUF page IDs
    if( ! is_page(array('278','279','280')) ) {
        wp_dequeue_style( 'wpuf-css' );
	wp_dequeue_script( 'wpuf-form' );
	wp_dequeue_script( 'google-maps' );
    }
}
// Set priority to run after scripts are enqeued by the plugin
add_action( 'wp_enqueue_scripts', 'disable_wpuf_scripts', 100 );
Viewing 5 Posts - 1 through 5 (of 5 total)