Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Stop loading wp-block-library-css when active #77

Closed
patrick-wc opened this issue Jan 24, 2019 · 9 comments
Closed

Suggestion: Stop loading wp-block-library-css when active #77

patrick-wc opened this issue Jan 24, 2019 · 9 comments

Comments

@patrick-wc
Copy link

Hi,

I noticed that even when these settings are applied:

Default editor for all users : Classic Editor
Allow users to switch editors : no

WordPress is still loading the wp-block-library-css CSS. Stylesheets are render blocking, so every site which isn't quite ready for Gutenberg yet, or has an old theme which disables it is needlessly delaying the user from seeing their page.

This could be fixed by dequeuing the stylesheet WordPress/gutenberg#7776 (comment) along with some extra checks: https://gist.github.com/toshotosho/109ec080dcffbb711be4d0f0db99d5f5

There is already a plugin support thread here https://wordpress.org/support/topic/gutenberg-block-css/

I like Gutenberg and will be ready to use it on new projects soon However I have a lot of old projects which will never use Gutenberg that are still maintained and kept up to date.

@azaozz
Copy link
Contributor

azaozz commented Jan 25, 2019

Yeah, this was suggested a few times. I'm reluctant to add it to this plugin as it may cause problems with themes that expect these styles, and it seems there will be more and more themes like that.

Removal of these styles can be done easily from another (custom?) plugin but I'd suggest it only for people that know what they are doing :)

@azaozz azaozz closed this as completed Jan 25, 2019
@azaozz
Copy link
Contributor

azaozz commented Jan 26, 2019

custom? or cloned? plugin...

Hehe, custom, as it will be just few lines of code.

There are several ways to add "hacks" to WP. For some (dumb) historical reasons the most popular is to add stuff to the theme's functions.php. That's no good but a lot of people still do it as it is all over the internet.

Much better option is to make a tiny plugin and drop it in mu-plugins dir in wp-content (create it if not there). These plugins always load (users cannot disable them) and should be just a file, not a subdir. However they show on the Plugins screen (so people won't forget about them) and are not overwritten when the theme is upgraded.

@ara303
Copy link

ara303 commented Mar 12, 2019

@azaozz - I realise that this is closed (sorry), but could we consider having the option to disable the Block Library CSS if the concern is that doing this by default might break themes? If a user is using the Classic Editor, there is a good chance they won't want the Block Library CSS, so is the option to disable it something worth considering?

Happy to make a separate issue specifically for an optional (and not enabled by default) toggle to disable the Block Library CSS if you'd like me to.

@hacknug
Copy link

hacknug commented Apr 16, 2019

Agree #wp-block-library-css shouldn't be enqueued when the block editor isn't used at all. Please consider reopening the issue as (imho) it doesn't make much sense to force anyone to add anything to their functions.php to dequeue something they didn't explicitly enqueue.

Just for future reference: #7776

@davegreenwp
Copy link

Have to agree with @edadams and @hacknug here, this really isn't something that we should have to take care of ourselves. I only spotted this as part of a routine yearly performance audit of one of our largest clients' sites; I had no idea this enqueue had been left in!

I know we're only talking about a single HTTP request of around ~6KB gzipped, it is a render blocking enqueue which would be nice to avoid out of the box.

@galbaras
Copy link

@azaozz Why is this issue closed? I too agree that since Gutenberg is now the default, and WordPress assumes it will need its resources, dequeuing them is the responsibility of the Classic Editor plugin.

Please also dequeue block-related resources added by other plugins, like WooCommerce and Jetpack.

@galbaras
Copy link

If it helps, here is the code that does it:

remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
remove_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );

I've tested this code in a plugin and it removes WP and WC scripts, so it should remove any other assets hooked onto 'enqueue_block_assets'.

@Erehr
Copy link

Erehr commented Aug 21, 2020

If it helps, here is the code that does it

To be safe you could wrap few conditions around too to check if plugin and settings are enabled.

if ( !in_array( 'classic-editor/classic-editor.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

    if( get_option('classic-editor-replace') == 'classic' && get_option('classic-editor-allow-users') == 'no') {

        remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
        remove_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );

    }

}

@galbaras
Copy link

@Erehr Not much point checking that the plugin is active. It clearly is.

I'm reluctant to add it to this plugin as it may cause problems with themes that expect these styles

@azaozz Would you be open to adding this as a setting for those that want it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants