JavaScript and CSS Performance
In this lesson
- How CSS and JavaScript block rendering
- How unused code and long tasks affect LCP and INP
- How to measure third-party script impact
- Which fixes to recommend to developers
Short answer
JavaScript and CSS slow pages when they block rendering, ship unused code, or run long tasks on the main thread. Audit them with Lighthouse diagnostics for render-blocking resources, unused CSS and JavaScript, total blocking time, and third-party impact, then recommend deferring scripts, removing unused code, and limiting heavy third-party tags.
A Quezon City clinic’s site loaded 41 JavaScript files: a page builder, two sliders, a chat widget, three analytics tags, a pop-up tool, and a booking plugin used on only one page. On a mid-range Android phone, tapping the menu took nearly a second to respond.
How CSS and JavaScript slow pages
- Render blocking: CSS and synchronous scripts in the head delay first paint and LCP.
- Unused code: whole libraries loaded for one feature, or every plugin’s files loaded on every page.
- Long tasks: heavy scripts keep the main thread busy, so taps wait. This hurts INP.
- Third parties: chat, ads, heatmaps, and social embeds often cost more than your own code.
What to check
In Lighthouse (PageSpeed Insights lab section), review:
- Eliminate render-blocking resources
- Reduce unused JavaScript and unused CSS
- Total Blocking Time and long main-thread tasks
- Reduce the impact of third-party code
- Minify CSS and JavaScript
Repeat on each template, since plugins often load per page type.
Recommendations developers can act on
- Add
deferto non-critical scripts. - Inline critical CSS, load the rest asynchronously.
- Load plugin files only on pages that use them.
- Break up long tasks and delay non-essential widgets until user interaction.
- Remove unused tags from Tag Manager.
Practice: what does this mainly hurt?
Sort each item into the right group.
-
Large CSS file blocking first paint
Answer: Loading (LCP).
-
Chat widget running long tasks on every tap
Answer: Responsiveness (INP).
-
Synchronous script in the head
Answer: Loading (LCP).
-
Heavy menu JavaScript on click
Answer: Responsiveness (INP).
-
Analytics tags firing complex code after each interaction
Answer: Responsiveness (INP).
Common mistakes
- Recommending “remove all JavaScript.” Be specific.
- Ignoring Tag Manager. Old tags pile up for years.
- Testing only on fast desktops.
Your action
Next, you will check mobile usability and responsive rendering.
Key terms
- Render-blocking resource
- A CSS or JavaScript file the browser must download and process before showing the page.
- Main thread
- The browser thread that runs JavaScript, layout, and painting. When it is busy, the page cannot respond.
- Long task
- Any main-thread task over 50 milliseconds, a common cause of poor INP.
- Third-party script
- Code loaded from another company, such as chat widgets, analytics, ad tags, and social embeds.
Questions beginners ask
What does defer do?
It downloads a script without blocking rendering and runs it after the HTML is parsed. Most non-critical scripts should use defer.
What is critical CSS?
The small set of styles needed for above-the-fold content, inlined in the head so the page renders before the full stylesheet loads.
How do I measure a third-party script's cost?
Lighthouse lists third-party usage and blocking time. You can also block a domain in Chrome DevTools and compare results.
Can SEO plugins fix this?
Performance plugins help with minification and deferring, but page builder bloat and heavy widgets usually need template or tool changes.
Related lessons
Want someone to handle SEO for your business while you learn? The team at Remar Digital can help.