P0Issue #4

Reduce Unused JS

ā“ What does it mean?

What does it mean? Unused JavaScript refers to JS code that is downloaded but never executed (or not needed on the current page). Examples include: Loading a large UI library but using only a small part of it. Shipping debugging scripts in production. Including third-party widgets (e.g., chat, analytics) that are not immediately required. This extra JS increases file size, delays parsing & execution, and slows down page rendering.

🚨 Why is it important for SEO?

Why is it important for SEO? Page Speed Impact → Large JS files delay First Contentful Paint (FCP) and Interaction to Next Paint (INP). Mobile Performance → Slower devices take longer to parse JS, hurting user experience. Core Web Vitals → Excess JS increases Total Blocking Time (TBT) and Time to Interactive (TTI). SEO Ranking Factor → Google rewards faster, responsive pages with better visibility.

āœ… How to Fix It

āœ… How to Fix It Audit JS usage → Use Chrome DevTools → Coverage Tab to see unused code. Code splitting → Load only the JavaScript needed for each page (tree-shaking). Remove unnecessary libraries → Replace large frameworks with lighter alternatives. Defer or async non-critical JS → Avoid blocking rendering. Lazy load third-party scripts → e.g., chatbots, analytics, ads only after interaction.

āŒ Bad Example

šŸ“Œ Example āŒ Bad (Lots of unused JS): <head> <!-- Loads entire jQuery (90KB) just to use one function --> <script src="https://cdn.com/jquery.min.js"></script> <script src="/js/app.js"></script> </head> <body> <button onclick="$('#msg').hide()">Hide Message</button> </body> Loads 90KB jQuery, but only uses .hide(). Adds unnecessary parsing & execution time.

āœ… Good Example

āœ… Good (Optimized JS): <head> <!-- Inline only the needed function --> <script defer> function hideMsg() { document.getElementById('msg').style.display = 'none'; } </script> </head> <body> <button onclick="hideMsg()">Hide Message</button> <p id="msg">Hello World!</p> </body> JS reduced from 90KB → 1KB. Page loads faster and interaction is immediate.

⚔ Result

⚔ Result Faster FCP, TTI & INP Lower JavaScript payload → especially beneficial on mobile Improved Core Web Vitals & SEO rankings