QrRapido/wwwroot/js/performance-optimizations.js
Ricardo Carneiro 9ba6da6270
All checks were successful
Deploy QR Rapido / test (push) Successful in 45s
Deploy QR Rapido / build-and-push (push) Successful in 13m11s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 1m20s
fix: ajustes performance
2025-09-21 01:48:26 -03:00

53 lines
2.0 KiB
JavaScript

// QR Rapido - Performance Optimizations
// Moved from inline scripts to improve LCP and reduce render-blocking
// Fallback inline para garantir funcionamento do theme toggle
document.addEventListener('DOMContentLoaded', function() {
// Theme toggle functionality
const btn = document.getElementById('theme-toggle');
if (btn) {
btn.onclick = function() {
const html = document.documentElement;
const current = html.getAttribute('data-theme') || 'light';
const newTheme = current === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
// Save preference to localStorage
localStorage.setItem('theme-preference', newTheme);
const icon = document.getElementById('theme-icon');
const text = document.getElementById('theme-text');
if (icon) {
icon.className = newTheme === 'dark' ? 'fas fa-moon' : 'fas fa-sun';
}
if (text) {
text.textContent = newTheme === 'dark' ? 'Escuro' : 'Claro';
}
};
}
// Load saved theme preference on page load
const savedTheme = localStorage.getItem('theme-preference');
if (savedTheme) {
document.documentElement.setAttribute('data-theme', savedTheme);
const icon = document.getElementById('theme-icon');
const text = document.getElementById('theme-text');
if (icon) {
icon.className = savedTheme === 'dark' ? 'fas fa-moon' : 'fas fa-sun';
}
if (text) {
text.textContent = savedTheme === 'dark' ? 'Escuro' : 'Claro';
}
}
});
// Optimize CSS loading fallback
document.addEventListener('DOMContentLoaded', function() {
// Ensure non-critical CSS loads properly
const printLinks = document.querySelectorAll('link[media="print"]');
printLinks.forEach(link => {
if (link.onload === null) {
link.media = 'all';
}
});
});