🚀 Performance Optimization Guide for Odoo Expertos

⚠️ Important: These optimizations are designed to improve performance WITHOUT breaking existing pages.

Current Performance Issues (PageSpeed Score: 63/100)

Quick Win #1: Use Optimized Server (Immediate Impact)

# Stop current server (Ctrl+C)
# Start optimized server with caching:
node server-optimized.js
✅ Adds HTTP caching headers
✅ Enables ETags for efficient revalidation
✅ Sets proper cache durations by file type
✅ No code changes needed

Quick Win #2: Add Performance Script to Homepage

Add this single line to your index.html before the closing </body> tag:

<script src="/performance-optimizer.js" defer></script>
✅ Adds lazy loading for images
✅ Defers D3.js loading
✅ Implements browser caching
✅ Preloads critical resources

Quick Win #3: Optimize Images (Manual but Effective)

For images currently loading from Pexels, modify your HTML:

<!-- Before (slow) -->
<img src="https://images.pexels.com/photos/1181406/pexels-photo-1181406.jpeg" alt="...">

<!-- After (fast with lazy loading) -->
<img class="lazy-bg" data-src="https://images.pexels.com/photos/1181406/pexels-photo-1181406.jpeg?auto=compress&cs=tinysrgb&w=800" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 600'%3E%3C/svg%3E" alt="..." loading="lazy">

Note: Adding ?auto=compress&cs=tinysrgb&w=800 reduces image size by ~70%

Quick Win #4: Defer Component Loading

Replace synchronous component loading in your HTML:

<!-- Before (blocks rendering) -->
<script src="/components/header.js"></script>
<script>document.write(createHeader());</script>

<!-- After (non-blocking) -->
<div id="header-placeholder"></div>
<script>
(function() {
var s = document.createElement('script');
s.src = '/components/header.js';
s.async = true;
s.onload = function() {
document.getElementById('header-placeholder').innerHTML = createHeader();
};
document.head.appendChild(s);
})();
</script>

Verification: Check Cache Status

Your Redis/Upstash cache API is configured but not being used. To verify it's working:

# Test cache API (in browser console):
fetch('/api/cache?action=stats')
.then(r => r.json())
.then(console.log);

# Expected response:
{ success: true, stats: { keys: X, connected: true } }

Expected Performance Improvements

Testing the Optimizations

  1. Start the optimized server: node server-optimized.js
  2. Open Chrome DevTools → Network tab
  3. Look for "from disk cache" or "304 Not Modified" on reload
  4. Check Performance tab for improved metrics
  5. Run PageSpeed Insights again after changes
💡 Pro Tip: Start with the optimized server (Quick Win #1) - it requires no code changes and provides immediate benefits!

Optional: Install Compression

npm install compression

# Then uncomment lines in server-optimized.js:
const compression = require('compression');
app.use(compression());

This will add gzip compression, reducing transfer sizes by ~70% for text files.