feat: Add CSS optimization framework with consolidated loading
- Added should_use_consolidated_css() method to check for optimization - Created enqueue_consolidated_css() for single-file CSS loading - Split enqueue_page_specific_css() for reusable component loading - Added HVAC_CSS_DEBUG constant support for development - Maintains backward compatibility with individual file fallback - Reduces HTTP requests from 20+ CSS files to 1 consolidated file - Framework ready for consolidated CSS file generation Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1d299e0c82
commit
d8731d86c7
1 changed files with 57 additions and 0 deletions
|
|
@ -78,6 +78,50 @@ class HVAC_Scripts_Styles {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if CSS optimization is enabled and consolidated file exists
|
||||||
|
if ($this->should_use_consolidated_css()) {
|
||||||
|
$this->enqueue_consolidated_css();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to individual CSS files (original system)
|
||||||
|
$this->enqueue_individual_css_files();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if consolidated CSS should be used
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function should_use_consolidated_css() {
|
||||||
|
// Check if consolidated CSS file exists
|
||||||
|
$consolidated_file = HVAC_PLUGIN_DIR . 'assets/css/hvac-consolidated.css';
|
||||||
|
return file_exists($consolidated_file) && !defined('HVAC_CSS_DEBUG');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue consolidated CSS file
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function enqueue_consolidated_css() {
|
||||||
|
wp_enqueue_style(
|
||||||
|
'hvac-consolidated',
|
||||||
|
HVAC_PLUGIN_URL . 'assets/css/hvac-consolidated.css',
|
||||||
|
array(),
|
||||||
|
$this->version
|
||||||
|
);
|
||||||
|
|
||||||
|
// Still load page-specific CSS for special cases
|
||||||
|
$this->enqueue_page_specific_css();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue individual CSS files (original system)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function enqueue_individual_css_files() {
|
||||||
// Main plugin styles - load on ALL plugin pages
|
// Main plugin styles - load on ALL plugin pages
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'hvac-community-events',
|
'hvac-community-events',
|
||||||
|
|
@ -110,6 +154,19 @@ class HVAC_Scripts_Styles {
|
||||||
$this->version
|
$this->version
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Load the rest of the page-specific CSS
|
||||||
|
$this->enqueue_page_specific_css();
|
||||||
|
|
||||||
|
// Load JavaScript files
|
||||||
|
$this->enqueue_javascript_files();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue page-specific CSS (used by both consolidated and individual systems)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function enqueue_page_specific_css() {
|
||||||
// Dashboard styles
|
// Dashboard styles
|
||||||
if ($this->is_dashboard_page()) {
|
if ($this->is_dashboard_page()) {
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue