rocklobster-in / contact-form-7

Contact Form 7 - Just another contact form plugin for WordPress.
Other
282 stars 138 forks source link

Improve the JavaScript and CSS loading adding minified versions #842

Open YordanSoares opened 2 years ago

YordanSoares commented 2 years ago

Currently, Contact Form 7 load the JavaScript and CSS files without minification. It would be a good enhancement to also provide minified versions of the JavaScripts and CSS assets, and load these versions by default, but allowing to load unminified version if the SCRIPT_DEBUG constant is set.

Related topic about this in the support forum at WordPress.org: https://wordpress.org/support/topic/unminified-javascript-and-css-files-3/

takayukister commented 2 years ago

Are you saying about admin scripts? If so, the JS will be minimized in 5.7.

I don't think minimizing CSS can make meaningful differences.

YordanSoares commented 2 years ago

Are you saying about admin scripts?

That's right. I also thought it could be great to include unminified versions following the proposal above, serving the right version based on the SCRIPT_DEBUG constant.

I mean something like this:

$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

wp_enqueue_style( 'contact-form-7-admin',
    wpcf7_plugin_url( 'admin/css/styles' . $suffix . '.css' ),
    array(), WPCF7_VERSION, 'all'
);

if ( wpcf7_is_rtl() ) {
    wp_enqueue_style( 'contact-form-7-admin-rtl',
        wpcf7_plugin_url( 'admin/css/styles-rtl' . $suffix . '.css' ),
        array(), WPCF7_VERSION, 'all'
    );
}

wp_enqueue_script( 'wpcf7-admin',
    wpcf7_plugin_url( 'admin/js/scripts' . $suffix . '.js' ),
    array( 'jquery', 'jquery-ui-tabs' ),
    WPCF7_VERSION, true
);

Repeating the same approach in all the relevant areas, like submodules, backend, etc. What do you think?

I don't think minimizing CSS can make meaningful differences.

However, it won't hurt! This will allow passing the warnings from performance scans that make users ask about it over and over again.