perf(TBT): Fase 2.3 - Eliminar código JS muerto (-96%)

Diagnóstico:
- main.js: ~95% código muerto (IDs no coinciden con DOM)
- header.js: ~90% código muerto (usa Bootstrap, no custom menu)

Cambios:
- main.js: 315 → 25 líneas (solo navbar scroll effect)
- header.js: DESHABILITADO completamente (343 líneas)
- Reducción total: ~633 líneas de JS innecesario

Impacto esperado: TBT -50-100ms

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-27 12:59:19 -06:00
parent 7e13678e0b
commit b0def25348
2 changed files with 43 additions and 342 deletions

View File

@@ -195,22 +195,28 @@ add_action('wp_enqueue_scripts', 'roi_enqueue_global_components', 7);
*
* NOTA: CSS del header se genera dinámicamente desde NavbarRenderer
* @see Public/Navbar/Infrastructure/Ui/NavbarRenderer.php
*
* DESHABILITADO: header.js (2025-11-27 - Optimización TBT Fase 2.3)
* Motivo: ~90% código muerto. Los elementos que busca no existen:
* - mobile-menu-toggle: no existe (sitio usa .navbar-toggler de Bootstrap)
* - mobile-menu: no existe (usa Bootstrap collapse)
* - masthead: no existe
* - Smooth scroll duplicado de main.js
* Reducción: ~343 líneas de JS eliminadas del parsing
*/
function roi_enqueue_header() {
// Header JS - with defer strategy
wp_enqueue_script(
'roi-header-js',
get_template_directory_uri() . '/Assets/js/header.js',
array(),
'1.0.0',
array(
'in_footer' => true,
'strategy' => 'defer',
)
);
}
add_action('wp_enqueue_scripts', 'roi_enqueue_header', 10);
// function roi_enqueue_header() {
// wp_enqueue_script(
// 'roi-header-js',
// get_template_directory_uri() . '/Assets/js/header.js',
// array(),
// '1.0.0',
// array(
// 'in_footer' => true,
// 'strategy' => 'defer',
// )
// );
// }
// add_action('wp_enqueue_scripts', 'roi_enqueue_header', 10);
/**
* Enqueue generic tables styles
@@ -268,42 +274,26 @@ add_action('wp_enqueue_scripts', 'roi_enqueue_video_styles', 11);
* Código único movido a: generic-tables.css, video.css
*/
function roi_enqueue_main_javascript() {
// Main JavaScript - navbar scroll effects and interactions
// Main JavaScript - navbar scroll effects
// OPTIMIZACIÓN TBT Fase 2.3: Eliminado ~300 líneas de código muerto
// Solo mantiene: navbar scroll effect (agrega clase 'scrolled')
wp_enqueue_script(
'roi-main-js',
get_template_directory_uri() . '/Assets/js/main.js',
array('roi-bootstrap-js'),
'1.0.3', // Cache bust: force remove defer with filter
true // Load in footer
);
// Localize script to pass theme URL to JavaScript
wp_localize_script(
'roi-main-js',
'roiheme',
'1.0.5', // TBT Fase 2.3: eliminado código muerto (~315 → ~25 líneas)
array(
'themeUrl' => get_template_directory_uri(),
'ajaxUrl' => admin_url('admin-ajax.php'),
'in_footer' => true,
'strategy' => 'defer',
)
);
}
add_action('wp_enqueue_scripts', 'roi_enqueue_main_javascript', 11);
/**
* Remove defer from roi-main-js to make wp_localize_script work
* WordPress 6.3+ adds defer automatically to footer scripts with dependencies
* but wp_localize_script requires synchronous execution
*/
function roi_remove_defer_from_main_js($tag, $handle) {
if ('roi-main-js' === $handle) {
// Remove defer and data-wp-strategy attributes
$tag = str_replace(' defer', '', $tag);
$tag = str_replace(' data-wp-strategy="defer"', '', $tag);
}
return $tag;
}
add_filter('script_loader_tag', 'roi_remove_defer_from_main_js', 20, 2);
// ELIMINADO: roi_remove_defer_from_main_js
// Motivo: wp_localize_script ya no se usa, main.js ahora puede usar defer
// Fecha: 2025-11-27 - Optimización TBT Fase 2
/**
* ELIMINADO: roi_enqueue_footer_styles