Will enqueuing Page specific CSS Files, using Conditional Logic, cause any problems? [on hold]

62
December 22, 2018, at 6:30 PM

I am working on a website, which currently has a very large CSS File being enqueued as follows:

function theme_name_enqueue_styles() {
    wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_name_enqueue_styles', 1 );

After reviewing the website, I can see that each page is only calling around 15%-20% of the total CSS classes. I would like to point out that each page's 15%-20% is made up of differing CSS Classes.

With this in mind, would it be okay to create page specific CSS Files and enqueue them as follows:

/*Enqueue Home Styles if on Homepage.*/
if( is_page('home') {
    function theme_name_enqueue_home_styles() {
        wp_enqueue_style( 'home-styles', get_stylesheet_directory_uri() . '/home-style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'theme_name_enqueue_home_styles', 1 );
} 
/*Enqueue Services Styles if on Services Page.*/
if( is_page('services') {
    function theme_name_enqueue_services_styles() {
        wp_enqueue_style( 'home-styles', get_stylesheet_directory_uri() . '/services-style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'theme_name_enqueue_services_styles', 1 );
} 

Whilst I understand this may result in more work in managing files, and is unlikely to be a suitable option when creating Themes to be managed by other people, this will be a website I will be solely responsible for. As such, willing to accept the additional management work, in return for a positive effect on Page Load speeds.

With this in mind, I was wondering if such an approach would:

  • Be counter productive, in that any savings with the CSS Files would be countered by the additional PHP Coding;
  • Cause any other unforeseen problems.
READ ALSO
How to set cookie for domain?

How to set cookie for domain?

A cookie is set when using localhost but it's not set in a domain

78
Javac Implementation: What jvm instructions does a method call produce?

Javac Implementation: What jvm instructions does a method call produce?

Assuming I have a method call site in javaWhat is the equivalent jvm bytecode (apart frm the call which is translated to invokevirtual/static e

50
How do I schedule emails using Quartz?

How do I schedule emails using Quartz?

I have a use case where I'll need to send emails around 100 users everyday in the eveningemail content for each user maybe different? (I am using Quartz scheduler to do this)

54
PHP Group Json Objects id and name [on hold]

PHP Group Json Objects id and name [on hold]

i searched in so and google, but i could not find any method for my problemThere are answers to similar questions

51