RenewLens.com JavaScript Defer and speed Optimization needs to be done on anydesk -- 2
Budget: $2 – $8 USD
WEBSITE SPEED FIX — renewlens.com
PRIORITY 1 — Script timing (biggest win)
1) Defer / async all non-critical JS
Goal: nothing runs before first paint except critical CSS + hero render.
Do:
Add defer to all app/theme scripts that are not required for initial render.
Use async only for scripts that do not depend on execution order (often pixels).
Shopify implementation notes:
In theme.liquid, identify scripts in <head>:
Analytics / pixels
Review widgets
Chat widget
Heatmaps/session replay
Upsells/recommendations
Convert:
<script src="..." ></script> → <script src="..." defer></script> (preferred)
Acceptance:
Page can paint hero + header before any third-party JS executes.
LCP improves immediately.
2) Delay heavy scripts until after interaction (or idle)
Goal: reviews/chat/upsells load only when the user shows intent.
Do:
Wrap third-party loads in one of these triggers:
after first scroll
after first click/tap
after idle using requestIdleCallback
or after 3–5 seconds timeout as fallback
Pattern:
Create a “deferred loader” snippet and call it conditionally:
requestIdleCallback(loadReviews)
window.addEventListener('scroll', loadChatOnce, { once: true })
Acceptance:
Lighthouse “Reduce JavaScript execution time” improves.
INP improves (less main-thread blocking early).
3) Remove render-blocking scripts from <head>
Goal: no third-party script blocks HTML parsing or CSSOM.
Do:
Move app scripts from <head> → just before </body> when possible.
If an app forces head injection, override by:
disabling “automatic install” mode in the app settings (if available)
or moving the snippet include from theme.liquid head to footer
Acceptance:
PageSpeed “Eliminate render-blocking resources” warning reduced.
No third-party script is loaded synchronously in head.
PRIORITY 2 — Page-level app control (huge win, zero app removals)
4) Scope apps by template/page type
Goal: Only run scripts where revenue happens.
Do:
Reviews app: product template only
Upsells: cart + checkout only (or cart drawer only)
Chat: after interaction, and optionally exclude homepage
Heatmaps/session replay: exclude homepage, exclude checkout, exclude high-traffic SEO pages if needed
Any “reco” widgets: only collection/product
Shopify conditionals (theme.liquid / sections):
template.name == 'product'
request.page_type (if theme supports it)
Acceptance:
Homepage becomes dramatically lighter without losing functionality site-wide.
PRIORITY 3 — Above-the-fold protection (LCP)
5) Hero image optimization (must be surgical)
Goal: LCP element loads instantly.
Do:
Ensure hero image file:
WebP/AVIF
< 200KB (target 120–180KB)
exact display dimensions (no 4000px monster scaled down)
Preload the hero image:
<link rel="preload" as="image" href="...">
Do not lazy-load the first visible hero image.
Use fetchpriority="high" on LCP image where supported.
Acceptance:
LCP drops. You see it in PageSpeed immediately.
6) Protect hero from JS interference
Goal: hero renders before any script tries to “enhance” it.
Do:
Remove sliders/carousels above the fold (or delay their initialization until after paint).
Avoid heavy animation libraries above the fold.
No app script should touch the hero container on load.
Acceptance:
Hero appears immediately even on slow mobile.
PRIORITY 4 — JavaScript hygiene
7) Reduce JS execution cost (theme cleanup)
Goal: less main-thread work, fewer long tasks.
Do:
Remove unused theme JS bundles/features:
quick view, predictive search, animations, sticky addons, etc if unused
Minify any custom JS you own.
Replace heavy animation with CSS only.
Reduce DOM size in hero/first section (massive nested divs hurt).
Acceptance:
Total Blocking Time improves.
INP improves.
PRIORITY 5 — Font optimization
8) Fonts: keep it brutally simple
Goal: avoid layout shifts + reduce early requests.
Do:
One font family max (2 only if you absolutely need it).
Remove unused font weights.
font-display: swap
Preload primary font file used above the fold.
Acceptance:
Faster first paint, fewer CLS shifts due to late font swap.
PRIORITY 6 — Layout stability (CLS)
9) Prevent layout shifts
Goal: stop stuff from jumping like it’s haunted.
Do:
Add explicit width/height or aspect-ratio to all images (especially above fold).
Lock header height (avoid announcement bar resizing late).
Reserve space for dynamic widgets (reviews badge, chat bubble, sticky cart).
Acceptance:
CLS gets near-zero.
PRIORITY 7 — Cleanup & verification
10) Re-test after each phase (don’t “optimize blindly”)
Do:
Run PageSpeed tests after each priority group:
Priority 1 changes
Priority 2 scoping
Hero/LCP
JS hygiene + fonts + CLS
Track:
LCP, INP, CLS
Total JS bytes + number of requests
“Main-thread work” in Lighthouse
Acceptance:
You know exactly which change produced which gain, so nothing gets “mysteriously worse.”
What’s the deep part you’re accidentally doing right
This plan is basically you enforcing a hierarchy of reality on your site:
First paint is truth
Apps are guests
Intent unlocks complexitye
PRIORITY 1 — Script timing (biggest win)
1) Defer / async all non-critical JS
Goal: nothing runs before first paint except critical CSS + hero render.
Do:
Add defer to all app/theme scripts that are not required for initial render.
Use async only for scripts that do not depend on execution order (often pixels).
Shopify implementation notes:
In theme.liquid, identify scripts in <head>:
Analytics / pixels
Review widgets
Chat widget
Heatmaps/session replay
Upsells/recommendations
Convert:
<script src="..." ></script> → <script src="..." defer></script> (preferred)
Acceptance:
Page can paint hero + header before any third-party JS executes.
LCP improves immediately.
2) Delay heavy scripts until after interaction (or idle)
Goal: reviews/chat/upsells load only when the user shows intent.
Do:
Wrap third-party loads in one of these triggers:
after first scroll
after first click/tap
after idle using requestIdleCallback
or after 3–5 seconds timeout as fallback
Pattern:
Create a “deferred loader” snippet and call it conditionally:
requestIdleCallback(loadReviews)
window.addEventListener('scroll', loadChatOnce, { once: true })
Acceptance:
Lighthouse “Reduce JavaScript execution time” improves.
INP improves (less main-thread blocking early).
3) Remove render-blocking scripts from <head>
Goal: no third-party script blocks HTML parsing or CSSOM.
Do:
Move app scripts from <head> → just before </body> when possible.
If an app forces head injection, override by:
disabling “automatic install” mode in the app settings (if available)
or moving the snippet include from theme.liquid head to footer
Acceptance:
PageSpeed “Eliminate render-blocking resources” warning reduced.
No third-party script is loaded synchronously in head.
PRIORITY 2 — Page-level app control (huge win, zero app removals)
4) Scope apps by template/page type
Goal: Only run scripts where revenue happens.
Do:
Reviews app: product template only
Upsells: cart + checkout only (or cart drawer only)
Chat: after interaction, and optionally exclude homepage
Heatmaps/session replay: exclude homepage, exclude checkout, exclude high-traffic SEO pages if needed
Any “reco” widgets: only collection/product
Shopify conditionals (theme.liquid / sections):
template.name == 'product'
request.page_type (if theme supports it)
Acceptance:
Homepage becomes dramatically lighter without losing functionality site-wide.
PRIORITY 3 — Above-the-fold protection (LCP)
5) Hero image optimization (must be surgical)
Goal: LCP element loads instantly.
Do:
Ensure hero image file:
WebP/AVIF
< 200KB (target 120–180KB)
exact display dimensions (no 4000px monster scaled down)
Preload the hero image:
<link rel="preload" as="image" href="...">
Do not lazy-load the first visible hero image.
Use fetchpriority="high" on LCP image where supported.
Acceptance:
LCP drops. You see it in PageSpeed immediately.
6) Protect hero from JS interference
Goal: hero renders before any script tries to “enhance” it.
Do:
Remove sliders/carousels above the fold (or delay their initialization until after paint).
Avoid heavy animation libraries above the fold.
No app script should touch the hero container on load.
Acceptance:
Hero appears immediately even on slow mobile.
PRIORITY 4 — JavaScript hygiene
7) Reduce JS execution cost (theme cleanup)
Goal: less main-thread work, fewer long tasks.
Do:
Remove unused theme JS bundles/features:
quick view, predictive search, animations, sticky addons, etc if unused
Minify any custom JS you own.
Replace heavy animation with CSS only.
Reduce DOM size in hero/first section (massive nested divs hurt).
Acceptance:
Total Blocking Time improves.
INP improves.
PRIORITY 5 — Font optimization
8) Fonts: keep it brutally simple
Goal: avoid layout shifts + reduce early requests.
Do:
One font family max (2 only if you absolutely need it).
Remove unused font weights.
font-display: swap
Preload primary font file used above the fold.
Acceptance:
Faster first paint, fewer CLS shifts due to late font swap.
PRIORITY 6 — Layout stability (CLS)
9) Prevent layout shifts
Goal: stop stuff from jumping like it’s haunted.
Do:
Add explicit width/height or aspect-ratio to all images (especially above fold).
Lock header height (avoid announcement bar resizing late).
Reserve space for dynamic widgets (reviews badge, chat bubble, sticky cart).
Acceptance:
CLS gets near-zero.
PRIORITY 7 — Cleanup & verification
10) Re-test after each phase (don’t “optimize blindly”)
Do:
Run PageSpeed tests after each priority group:
Priority 1 changes
Priority 2 scoping
Hero/LCP
JS hygiene + fonts + CLS
Track:
LCP, INP, CLS
Total JS bytes + number of requests
“Main-thread work” in Lighthouse
Acceptance:
You know exactly which change produced which gain, so nothing gets “mysteriously worse.”
What’s the deep part you’re accidentally doing right
This plan is basically you enforcing a hierarchy of reality on your site:
First paint is truth
Apps are guests
Intent unlocks complexitye
Related categories:
PHP
JavaScript
CSS
HTML
Shopify
Web Development
Frontend Development
A/B Testing