Skip to content

Update GTM script loading to lazyOnload#275

Open
finrunsfar wants to merge 3 commits into
devfrom
pagespeed-tweak
Open

Update GTM script loading to lazyOnload#275
finrunsfar wants to merge 3 commits into
devfrom
pagespeed-tweak

Conversation

@finrunsfar
Copy link
Copy Markdown
Contributor

@finrunsfar finrunsfar commented Apr 14, 2026


Note

Medium Risk
Tweaks load priority for images, videos, and GTM, which can change perceived performance and analytics firing timing across key pages. Main risk is unintended regressions in above-the-fold rendering or missing/late tracking on production.

Overview
Improves perceived performance by adjusting what loads eagerly vs lazily across the site.

Blog posts now render the frontmatter image as an early, priority Next Image hero (and removes the duplicated in-body markdown image in matlab-alternatives.md) to boost LCP. Markdown image rendering is updated to set loading/fetchPriority/decoding attributes (with a special-case to eagerly load the first/hero image).

Moves the global homepage poster preload out of RootLayout to avoid hurting LCP on non-home routes, swaps the matlab-online hero from a plain <video autoPlay> to LazyVideo to defer video loading until in-view, and changes GoogleTagManager script loading from afterInteractive to lazyOnload.

Reviewed by Cursor Bugbot for commit 50802dd. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
runmat Ready Ready Preview, Comment, Open in v0 Apr 14, 2026 11:23pm

Request Review

Comment thread website/app/layout.tsx Outdated
@finrunsfar finrunsfar marked this pull request as draft April 14, 2026 17:32
@finrunsfar finrunsfar marked this pull request as ready for review April 14, 2026 17:34
@finrunsfar finrunsfar changed the title Remove GoogleAnalytics and update GTM script loading to lazyOnload Update GTM script loading to lazyOnload Apr 14, 2026
- Moved poster preload link from RootLayout to improve LCP on non-homepage routes.
- Added early rendering of frontmatter image in blog posts to enhance LCP.
- Replaced video element with LazyVideo component in MatlabOnlinePage for better performance.
- Updated MarkdownRenderer to conditionally load images with eager loading for hero images.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 50802dd. Configure here.

// Next.js Image component handles lazy loading better by default,
// but for markdown we'll use a standard img tag with better attributes
// The hero image or first image should usually be eager loaded
const isFirstImage = src?.includes('free-matlab-alternatives-2026') || false; // Hacky way to detect hero
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded isFirstImage check is dead code on arrival

Low Severity

The isFirstImage check hardcodes 'free-matlab-alternatives-2026' to eagerly load a specific hero image, but the same commit removes that image from the markdown content of matlab-alternatives.md and moves it to a frontmatter-driven Image component in page.tsx. This detection will never match any image actually rendered through MarkdownRenderer, making the entire isFirstImage conditional (and its fetchPriority/loading branching) dead code.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 50802dd. Configure here.

priority={true}
/>
</div>
)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hero image duplicates inline image on multiple blog posts

High Severity

The new frontmatter-driven hero image renders for every blog post that has an image field, but the inline markdown image was only removed from matlab-alternatives.md. At least three other posts (from-ad-hoc-checkpoints-to-reliable-large-data-persistence, in-defense-of-matlab-whiteboard-style-code, introducing-runmat-cloud) have the same image in both frontmatter and their markdown body, causing the image to appear twice on those pages.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 50802dd. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant