Just detect front end js and css
-
I actually like this plugin, but how do I make it detect only the js and css front end on asset optimization? because the js and css dashboards are also detected, too many and sometimes loading is stuck and finally i delete this plugin.
-
Hi @sonisitez,
I hope you are doing well today!
You can exclude any file you don’t want to optimize in plugin exclusion settings.
Please check exclusions section on below documentation
https://wpmudev.com/docs/wpmu-dev-plugins/hummingbird/#assets-automatic-configsKind regards,
ZaferFor example, I use manual optimize, but the js and css files from the back end are also loaded, there are almost hundreds and hummingbirds are stuck/crashes, how do I prevent js and css files from the backend from being included in the list? it’s a waste..
Hi @sonisitez
I hope you are doing well,
Can you please share a screenshot of which CSS from the backend it is detecting?
By default, it should only detect the frontend files which are called in the wp_enqueue_scripts hook https://developer.wordpress.org/reference/hooks/wp_enqueue_scripts/ while backend uses a different hook.
Best Regards
Patrick FreitasThis is the screenshot, using NGINX and php 8.1
https://ibb.co/z8NzQm1I think hummingbird will become no 1 in the market if they can do input asset manually, for compress or merge.
Hi @sonisitez
Thank you.
Those detected Assets are actually frontend assets https://monosnap.com/file/gx1c7JpSOfgBkcc2nRRtKajucE2MeN
https://monosnap.com/file/pKBKlrwyHl7aEn4BU1vCRCelRlTvqMI agree two of the reported Admin bar and Dashicons are loaded only when the user is logged in and we should not worry about those, maybe even report them in the plugin.
We will share this feedback with our developers.
But some assets are also loaded when you are logged out:
https://monosnap.com/file/wW5ydYyxuCL1c8RDUkBTywoGxXyEYtI’ve pinged our developers to verify if we have any available hooks to disable those assets from the Assets optimization page.
Best Regards
Patrick FreitasHi @sonisitez
Could you please try the following code:
<?php add_action( 'plugins_loaded', function() { if ( ! class_exists( 'Hummingbird\\WP_Hummingbird' ) ) { return; // Hummingbird is not installed/enabled. } if ( ! class_exists( 'Hummingbird_Non_Frontend_Assets_Excluder' ) ) { class Hummingbird_Non_Frontend_Assets_Excluder { private static $instance; private $excluded_handles = array(); // Set this to TRUE to prevent minify and combine the // excluded items (Use only if you know what you are doing). const PREVENT_MINIFY_AND_COMBINE = FALSE; public static function get() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } public function __construct() { add_filter( 'wphb_minification_display_enqueued_file', array( $this, 'should_display_enqueued_file' ), 10, 3 ); if ( self::PREVENT_MINIFY_AND_COMBINE ) { add_filter( 'wphb_minify_resource', array( $this, 'should_minify_resource' ), 10, 4 ); add_filter( 'wphb_combine_resource', array( $this, 'should_combine_resource' ), 10, 3 ); } } private function is_frontend_asset( $src ) { $current_theme_dir = get_template_directory(); $current_theme_url = get_template_directory_uri(); if ( false !== strpos( $src, basename( WP_CONTENT_DIR ) . '/themes' ) && 0 !== strpos( $src, $current_theme_dir ) && 0 !== strpos( $src, $current_theme_url ) ) { return false; // Non-active theme assets. } if ( false !== strpos( $src, '/wp-includes/' ) || false !== strpos( $src, '/wp-admin/' ) ) { return false; // Admin assets. } return true; } public function should_display_enqueued_file( $value, $item, $type ) { if ( ! $this->is_frontend_asset( $item['src'] ) ) { $this->excluded_handles[ $item['handle'] ] = $type; return false; } return $value; } public function should_minify_resource( $value, $handle, $type, $url ) { if ( ! $this->is_frontend_asset( $url ) ) { $this->excluded_handles[ $handle ] = $type; return false; } return $value; } public function should_combine_resource( $value, $handle, $type ) { if ( isset( $this->excluded_handles[ $handle ] ) ) { return false; } return $value; } } Hummingbird_Non_Frontend_Assets_Excluder::get(); } });
Add it as a mu-plugin:
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins then re-check the Assets files, it will prevent those unwished files from getting in Assets Optimization.
Best Regards
Patrick FreitasThis is just a suggestion because I care about Hummingbird and I think it has a very good concept, if possible have other options for manual assets and everything can be done manually, both input assets, compress, and merge, because sometimes not all css and js files can be compress or merge to run properly, and that way we can optimize as needed. Thank You.
Hi @sonisitez
Thank you for response!
My colleague already forwarded this suggestion to our Hummingbird Team so developers will look into it.
We are constantly working on improving the plugin and this sounds like a really nice thing to implement. I don’t have ETA but it will surely be looked into and taken into consideration with future updates.
Best regards,
AdamOh yes, I forgot to say the way Hummingbird now handles assets is very problematic for sites that are already in production, because Hummingbird not only takes WP dashboard assets but backend assets from plugins. Imagine I have 15 plugins and each plugin has assets of about 5-10 CSS/JS, and it’s all displayed there. There will be hundreds of assets that are visible and very dizzying when they are not needed. Hopefully my suggestion can be considered.
Hello @sonisitez !
Thank you for the additional feedback! We’ll pass it over to our Hummingbird team for further review as well.
Kind regards,
PawelHi @sonisitez,
Since this is already passed to our Hummingbird team’s attention for further review on its possibilities and since you don’t have any further queries, I’ll mark this thread as resolved for now.
Please feel free to re-open the thread if you need further assistance.
Best Regards
Nithin
- The topic ‘Just detect front end js and css’ is closed to new replies.