• Hi,

    Currently, I am fighting to remove every single unused bit of data when loading my front-page. I am trying to score high in google page insight under mobile view.

    I notice there are 3 unused CSS load at my front-page:

    wp-includes/css/dist/components/style.min.css?ver=5.7
    wp-content/cache/min/1/ajax/libs/font-awesome/5.15.1/css/all.min.css?ver=1616594077
    wp-includes/css/dist/block-editor/style.min.css?ver=5.7

    Is there a function that can dequeue these stylesheets?

    function dequeue_unused_css() {
         if (is_front_page()) {
    	wp_dequeue_style('components');
            wp_dequeue_style('block-editor');
         }
      }
    add_action('wp_enqueue_scripts', 'dequeue_unused_css', 20);
    • This topic was modified 3 years, 11 months ago by tianxl.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hi @tianxl,
    First of all I think there is some error with your cache plugin or theme because it is unnecessarily loading too many css files

    <link rel=’preload’ href=’https://tianxuan.ca/wp-includes/css/dist/block-editor/style.min.css?ver=5.7′ data-rocket-async=”style” as=”style” onload=”this.onload=null;this.rel=’stylesheet'” media=’all’ />
    <link rel=’preload’ href=’https://tianxuan.ca/wp-includes/css/dist/nux/style.min.css?ver=5.7′ data-rocket-async=”style” as=”style” onload=”this.onload=null;this.rel=’stylesheet'” media=’all’ />
    <link rel=’preload’ href=’https://tianxuan.ca/wp-includes/css/dist/editor/style.min.css?ver=5.7′ data-rocket-async=”style” as=”style” onload=”this.onload=null;this.rel=’stylesheet'” media=’all’ />
    <link rel=’preload’ href=’https://tianxuan.ca/wp-includes/css/dist/block-library/style.min.css?ver=5.7′ data-rocket-async=”style” as=”style” onload=”this.onload=null;this.rel=’stylesheet'” media=’all’ />
    <link rel=’preload’ href=’https://tianxuan.ca/wp-includes/css/dist/block-library/theme.min.css?ver=5.7′ data-rocket-async=”style” as=”style” onload=”this.onload=null;this.rel=’stylesheet'” media=’all’ />

    These /wp-includes/ files should never load on front-end.

    Coming to your question, the code is correct. Trying increasing 20 to something like 330 and also wp_deregister_style:

    function dequeue_unused_css() {
         if (is_front_page() || is_home()) {
    	wp_dequeue_style('components');
            wp_deregister_style('components');
            wp_dequeue_style('block-editor');
            wp_deregister_style('block-editor');
         }
      }
    add_action('wp_enqueue_scripts', 'dequeue_unused_css', 330);
    • This reply was modified 3 years, 11 months ago by Gaurav Tiwari.
    • This reply was modified 3 years, 11 months ago by Gaurav Tiwari.
Viewing 1 replies (of 1 total)
  • The topic ‘Remove stylesheet from front-page’ is closed to new replies.