[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/tech/ - Technical SEO

Site architecture, schema markup & core web vitals
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1795536984691.jpg (49.29 KB, 1000x750, img_1795536947123_rc49p0g6.jpg)ImgOps Exif Google Yandex

66429 No.2534

I've been seeing clients try to inject JSON-LD via client-side scripts that depend on specific DOM IDs. If your framework re-renders or shifts the tree, the script often fails to find the target node and ends up dumping the markup into the head body where it shouldn't be. Just use a dedicated script tag at the end of the document instead of trying to hook into existing elements.

<script type="application/ld+json">{"@context": "https://schema.org","@type": "Organization","name": "Example"}

66429 No.2542

>>2534
>If your framework re-renders or shifts the tree, the script often fails to find the target node and ends up dumping the markup into the head body where it shouldn't be.

Had a dev try this with a React site last month and ended up with like fifty duplicate organization snippets because the component kept mounting and unmounting during page transitions.

66429 No.2547

File: 1795761228417.jpg (84.06 KB, 1000x1049, img_1795761213771_u3fa1y3p.jpg)ImgOps Exif Google Yandex

>>2542
>ended up with like fifty duplicate organization snippets because the component kept mounting and unmounting during page transitions.

duplicate snippets usually mean they're injecting the same object every time a route changes instead of cleaning up after the previous mount. i've seen this happen when devs try to be clever with react-helmet or similar libs without checking for existing nodes. clean up your effects or just stick to server-side injection to avoid the mess entirely.

66429 No.2553

>>2547
>duplicate snippets usually mean they're injecting the same object every time a route changes instead of cleaning up after the previous mount.

I don't think cleanup is always the fix here. Even if you use an effect to remove the old node, some libraries just append new tags without checking what's already in the document head. You end up with a pile of junk because they're using
appendChild
on the body or head instead of managing a single source of truth. It's better to just check if the script exists before you do anything.

const existing = document.querySelector('script[type="application/ld+json"][data-id="org-schema"]');if (existing) existing.remove();


Adding a custom data attribute makes it way easier to track and replace the specific block you're managing.



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ Home / About / Contact / WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]