diff --git a/docs/spec/auto-lightbox.md b/docs/spec/auto-lightbox.md index 79c8e548f742..b4fcf5fbb86e 100644 --- a/docs/spec/auto-lightbox.md +++ b/docs/spec/auto-lightbox.md @@ -53,7 +53,7 @@ To disable it on a particular document section: ``` -Or to disable it for your entire document altogether: +To disable it for your entire document altogether: ```html @@ -61,6 +61,14 @@ Or to disable it for your entire document altogether: ``` +Or to prevent automatically loading of `amp-auto-lightbox` script on page load: + +```html + + + +``` + If you'd like manual tuning of disabled/enabled images and/or grouping, please use [`amp-lightbox-gallery`](https://amp.dev/documentation/components/amp-lightbox-gallery) directly. diff --git a/src/auto-lightbox.js b/src/auto-lightbox.js index 80b51fe3f6d8..82220fcbe786 100644 --- a/src/auto-lightbox.js +++ b/src/auto-lightbox.js @@ -27,7 +27,13 @@ export const AutoLightboxEvents_Enum = { export function installAutoLightboxExtension(ampdoc) { const {win} = ampdoc; // Only enabled on single documents tagged as or . - if (!isAmphtml(win.document) || !ampdoc.isSingleDoc()) { + if ( + !isAmphtml(win.document) || + !ampdoc.isSingleDoc() || + // Prevent loading auto lightbox when disabled using 'data-amp-auto-lightbox-disable' attribute (#37854) + // Check if HTML Tag has 'data-amp-auto-lightbox-disable' attribute + win.document.documentElement.hasAttribute('data-amp-auto-lightbox-disable') + ) { return; } chunk(