# Stop current server (Ctrl+C)
# Start optimized server with caching:
node server-optimized.js
Add this single line to your index.html before the closing </body> tag:
<script src="/performance-optimizer.js" defer></script>
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%
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>
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 } }
node server-optimized.js
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.