diff --git a/customize/custom-scripts.mdx b/customize/custom-scripts.mdx index b465bb2d5..92a6c8bb1 100644 --- a/customize/custom-scripts.mdx +++ b/customize/custom-scripts.mdx @@ -363,6 +363,14 @@ Custom JavaScript lets you add custom executable code globally. It is the equiva Mintlify includes any `.js` file inside your content directory on every page of your site. Custom JavaScript files run after the page becomes interactive. You cannot scope them to specific pages. When you include multiple `.js` files, they run without a guaranteed order. +To run code only on certain pages, branch on the current path inside your script. Mintlify sets `data-current-path` on `` and updates it on client-side navigation, so it stays in sync during SPA transitions: + +```js Example per-page script +if (document.documentElement.dataset.currentPath?.startsWith('/api-reference/')) { + // Run only on pages under /api-reference/. +} +``` + To load a third-party script, inject a `