manifest / performance / pdf-lazy-loader
PDF Lazy Loader
Defers PDF Embedder output behind a lightweight click-to-load facade with optional Cloudflare Turnstile check. No PDF/viewer assets are loaded until the visitor clicks "View PDF".
★ 0stars
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/gemuzkm/pdf-lazy-loader/archive/refs/heads/main.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
PDF Lazy Loader v1.3.1
WordPress plugin that defers PDF Embedder / PDF Embedder Premium output behind a lightweight click-to-load facade. Nothing PDF-related — viewer iframe, PDF file, viewer CSS/JS — is requested until the visitor clicks View PDF (and, optionally, passes Cloudflare Turnstile). This keeps pages light and hides PDFs from naive bots.
Features
- Server-rendered facade: the placeholder is part of the HTML (
the_contentfilter) — visible before any JS runs, no layout shift (CLS), page-cache friendly - Zero PDF assets on page load: PDF Embedder CSS/JS (including
pdfemb-fullscreen.min.cssenqueued insideViewer::render()) are captured and loaded only on click - Localized data preserved:
wp_localize_script()/wp_add_inline_script()data attached to PDF Embedder handles (e.g.pdfemb_trans) is carried over, so deferred scripts work exactly as when loaded normally - Fast click-to-view: minimum spinner time runs in parallel with asset loading (default 300 ms); static viewer assets are preloaded on hover / focus / touch
- Cloudflare Turnstile: optional verification before the PDF loads (widget script is also preloaded on intent)
- Server-side Turnstile verification (optional): token checked via Cloudflare
siteverify; the page contains only an AES-256-GCM encrypted reference, the PDF URL is released by a REST endpoint after verification - URL obfuscation: iframe
srcis replaced by an XOR + Base64 copy indata-pdf-lazy-original-src-enc - Responsive facade: heights per breakpoint via CSS custom properties and
@media(no resize listeners) - Accessible by default (WCAG AA): button/icon colors are auto-darkened (same hue) until white text reaches 4.5:1; all facade texts meet 4.5:1; no heading tags in the facade (does not break the page heading outline)
- No render-blocking request: facade CSS (~3 KB) is inlined in
<head>; frontend JS is minified (pdf-lazy-loader.min.js, ~4 KB gzip) and deferred - Download button (optional), Debug mode, translatable strings (
pdf-lazy-loadertext domain) - WordPress 7.x: tested up to 7.1, requires PHP 7.4+, script tags via
wp_get_inline_script_tag()(CSP-nonce friendly), frontend JS withdeferstrategy
How It Works
Page Load (before user interaction)
- Detection —
pdf_lazy_loader_has_pdf_iframes()checks every post of the main query (single pages, blog index, archives, search). Result is memoized per request (tri-state); pages without PDF are not touched at all — no CSS/JS/inline script from this plugin is printed there the_content:999— each PDF iframe gets itssrcremoved (obfuscated copy kept in a data attribute), the classpll-iframe-hidden, and a server-side facade is printed right before it- Layer 1 —
wp_enqueue_scripts:999: queued PDF Embedder styles/scripts are collected (final URL incl.?ver=, deps in order, localized data, inline before/after) and dequeued - Layer 2 —
wp_footer:1: same collection after all shortcodes ran — catchespdf-fullscreen(pdfemb-fullscreen.min.css) enqueued insideViewer::render() - ob_start —
template_redirect:1: onepreg_replace_callbackpass strips any PDF Embedder<link>/`