Plugin Directory

Changeset 3447066


Ignore:
Timestamp:
01/26/2026 12:08:09 PM (3 weeks ago)
Author:
coozywana
Message:

Update to version 2.4.1 from GitHub

Location:
staticdelivr
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • staticdelivr/tags/2.4.1/README.txt

    r3447061 r3447066  
    66Tested up to: 6.9
    77Requires PHP: 7.4
    8 Stable tag: 2.3.0
     8Stable tag: 2.4.1
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    240240== Changelog ==
    241241
     242= 2.4.1 =
     243* Fixed: Resolved an issue where lazy-loaded images could fail silently without triggering the fallback mechanism (Browser Intervention).
     244* Improved: Fallback script now aggressively removes `srcset` and `loading` attributes to force browsers to retry failed images immediately.
     245* New: Added a "Sweeper" function to automatically detect and repair broken images that were missed by standard error listeners.
     246* Fixed: Improved error detection logic to prioritize `currentSrc`, ensuring failures in responsive thumbnails are caught even if the main src is valid.
     247
    242248= 2.4.0 =
    243249* New: Smart Dimension Detection. The plugin now automatically identifies missing width and height attributes for WordPress images and restores them using attachment metadata.
     
    403409== Upgrade Notice ==
    404410
     411= 2.4.1 =
     412Critical fix for images failing to load on modern browsers. This update handles "Lazy Load Interventions" and ensures the fallback mechanism works 100% of the time. Recommended for all users.
     413
    405414= 2.4.0 =
    406415This update introduces Smart Dimension Detection to automatically fix PageSpeed Insights warnings and improve your site's SEO and CLS scores. Highly recommended for all users.
  • staticdelivr/tags/2.4.1/includes/class-staticdelivr-fallback.php

    r3446519 r3447066  
    108108        $ajax_url = admin_url( 'admin-ajax.php' );
    109109        $nonce    = wp_create_nonce( 'staticdelivr_failure_report' );
    110 
    111110        $debug_enabled = get_option( STATICDELIVR_PREFIX . 'debug_mode', false ) ? 'true' : 'false';
    112111
     
    116115        $script .= "    var SD_NONCE = '%s';\n";
    117116        $script .= "\n";
    118         $script .= "    function log() {\n";
    119         $script .= "        if (SD_DEBUG && console && console.log) {\n";
    120         $script .= "            console.log.apply(console, ['[StaticDelivr]'].concat(Array.prototype.slice.call(arguments)));\n";
    121         $script .= "        }\n";
    122         $script .= "    }\n";
     117        $script .= "    function log() { if (SD_DEBUG && console) console.log.apply(console, ['[StaticDelivr]'].concat(Array.prototype.slice.call(arguments))); }\n";
    123118        $script .= "\n";
    124119        $script .= "    function reportFailure(type, url, original) {\n";
     
    130125        $script .= "            data.append('url', url);\n";
    131126        $script .= "            data.append('original', original || '');\n";
    132         $script .= "\n";
    133         $script .= "            if (navigator.sendBeacon) {\n";
    134         $script .= "                navigator.sendBeacon(SD_AJAX_URL, data);\n";
    135         $script .= "            } else {\n";
    136         $script .= "                var xhr = new XMLHttpRequest();\n";
    137         $script .= "                xhr.open('POST', SD_AJAX_URL, true);\n";
    138         $script .= "                xhr.send(data);\n";
    139         $script .= "            }\n";
     127        $script .= "            if (navigator.sendBeacon) navigator.sendBeacon(SD_AJAX_URL, data);\n";
     128        $script .= "            else { var xhr = new XMLHttpRequest(); xhr.open('POST', SD_AJAX_URL, true); xhr.send(data); }\n";
    140129        $script .= "            log('Reported failure:', type, url);\n";
    141         $script .= "        } catch(e) {\n";
    142         $script .= "            log('Failed to report:', e);\n";
    143         $script .= "        }\n";
     130        $script .= "        } catch(e) { log('Failed to report:', e); }\n";
    144131        $script .= "    }\n";
    145132        $script .= "\n";
     
    150137        $script .= "            if (!attr || !attr.name) continue;\n";
    151138        $script .= "            if (attr.name === 'src' || attr.name === 'href' || attr.name === 'data-original-src' || attr.name === 'data-original-href') continue;\n";
    152         $script .= "            try {\n";
    153         $script .= "                to.setAttribute(attr.name, attr.value);\n";
    154         $script .= "            } catch(e) {}\n";
     139        $script .= "            try { to.setAttribute(attr.name, attr.value); } catch(e) {}\n";
    155140        $script .= "        }\n";
    156141        $script .= "    }\n";
     
    161146        $script .= "        try {\n";
    162147        $script .= "            var urlObj = new URL(cdnUrl);\n";
    163         $script .= "            var originalUrl = urlObj.searchParams.get('url');\n";
    164         $script .= "            if (originalUrl) {\n";
    165         $script .= "                log('Extracted original URL from query param:', originalUrl);\n";
    166         $script .= "                return originalUrl;\n";
    167         $script .= "            }\n";
    168         $script .= "        } catch(e) {\n";
    169         $script .= "            log('Failed to parse CDN URL:', cdnUrl, e);\n";
    170         $script .= "        }\n";
    171         $script .= "        return null;\n";
     148        $script .= "            return urlObj.searchParams.get('url');\n";
     149        $script .= "        } catch(e) { return null; }\n";
     150        $script .= "    }\n";
     151        $script .= "\n";
     152        $script .= "    // --- CORE FIXER LOGIC ---\n";
     153        $script .= "    function performFallback(el, original, failedUrl) {\n";
     154        $script .= "        if (el.getAttribute('data-sd-fallback') === 'done') return;\n";
     155        $script .= "        el.setAttribute('data-sd-fallback', 'done');\n";
     156        $script .= "        log('Forcing fallback on:', original);\n";
     157        $script .= "\n";
     158        $script .= "        // CRITICAL: Remove srcset/loading to bypass browser interventions\n";
     159        $script .= "        el.removeAttribute('srcset');\n";
     160        $script .= "        el.removeAttribute('sizes');\n";
     161        $script .= "        el.removeAttribute('loading');\n";
     162        $script .= "        el.src = original;\n";
     163        $script .= "\n";
     164        $script .= "        if (failedUrl) reportFailure('image', failedUrl, original);\n";
    172165        $script .= "    }\n";
    173166        $script .= "\n";
     
    179172        $script .= "        if (!tagName) return;\n";
    180173        $script .= "\n";
    181         $script .= "        // Only handle elements we care about\n";
    182         $script .= "        if (tagName !== 'SCRIPT' && tagName !== 'LINK' && tagName !== 'IMG') return;\n";
    183         $script .= "\n";
    184         $script .= "        // Get the failed URL\n";
    185         $script .= "        var failedUrl = '';\n";
    186         $script .= "        if (tagName === 'IMG') failedUrl = el.src || el.currentSrc || '';\n";
    187         $script .= "        else if (tagName === 'SCRIPT') failedUrl = el.src || '';\n";
    188         $script .= "        else if (tagName === 'LINK') failedUrl = el.href || '';\n";
    189         $script .= "\n";
    190         $script .= "        // Only handle StaticDelivr URLs\n";
    191         $script .= "        if (failedUrl.indexOf('cdn.staticdelivr.com') === -1) return;\n";
     174        $script .= "        var failedUrl = (tagName === 'IMG') ? (el.currentSrc || el.src) : (el.href || el.src);\n";
     175        $script .= "        if (!failedUrl || failedUrl.indexOf('cdn.staticdelivr.com') === -1) return;\n";
    192176        $script .= "\n";
    193177        $script .= "        log('Caught error on:', tagName, failedUrl);\n";
    194178        $script .= "\n";
    195         $script .= "        // Prevent double-processing\n";
    196         $script .= "        if (el.getAttribute && el.getAttribute('data-sd-fallback') === 'done') return;\n";
    197         $script .= "\n";
    198         $script .= "        // Get original URL\n";
    199179        $script .= "        var original = el.getAttribute('data-original-src') || el.getAttribute('data-original-href');\n";
    200180        $script .= "        if (!original) original = extractOriginalFromCdnUrl(failedUrl);\n";
    201         $script .= "\n";
    202         $script .= "        if (!original) {\n";
    203         $script .= "            log('Could not determine original URL for:', failedUrl);\n";
    204         $script .= "            return;\n";
    205         $script .= "        }\n";
    206         $script .= "\n";
    207         $script .= "        el.setAttribute('data-sd-fallback', 'done');\n";
    208         $script .= "        log('Falling back to origin:', tagName, original);\n";
    209         $script .= "\n";
    210         $script .= "        // Report the failure\n";
    211         $script .= "        var reportType = (tagName === 'IMG') ? 'image' : 'asset';\n";
    212         $script .= "        reportFailure(reportType, failedUrl, original);\n";
    213         $script .= "\n";
    214         $script .= "        if (tagName === 'SCRIPT') {\n";
     181        $script .= "        if (!original) return;\n";
     182        $script .= "\n";
     183        $script .= "        if (tagName === 'IMG') {\n";
     184        $script .= "            performFallback(el, original, failedUrl);\n";
     185        $script .= "        } else if (tagName === 'SCRIPT') {\n";
     186        $script .= "            el.setAttribute('data-sd-fallback', 'done');\n";
     187        $script .= "            reportFailure('asset', failedUrl, original);\n";
    215188        $script .= "            var newScript = document.createElement('script');\n";
    216189        $script .= "            newScript.src = original;\n";
    217         $script .= "            newScript.async = el.async;\n";
    218         $script .= "            newScript.defer = el.defer;\n";
    219         $script .= "            if (el.type) newScript.type = el.type;\n";
    220         $script .= "            if (el.noModule) newScript.noModule = true;\n";
    221         $script .= "            if (el.crossOrigin) newScript.crossOrigin = el.crossOrigin;\n";
    222190        $script .= "            copyAttributes(el, newScript);\n";
    223         $script .= "            if (el.parentNode) {\n";
    224         $script .= "                el.parentNode.insertBefore(newScript, el.nextSibling);\n";
    225         $script .= "                el.parentNode.removeChild(el);\n";
     191        $script .= "            if(el.parentNode) { el.parentNode.insertBefore(newScript, el.nextSibling); el.parentNode.removeChild(el); }\n";
     192        $script .= "        } else if (tagName === 'LINK') {\n";
     193        $script .= "            el.setAttribute('data-sd-fallback', 'done');\n";
     194        $script .= "            reportFailure('asset', failedUrl, original);\n";
     195        $script .= "            el.href = original;\n";
     196        $script .= "        }\n";
     197        $script .= "    }\n";
     198        $script .= "\n";
     199        $script .= "    // --- THE SWEEPER (Catches silent failures) ---\n";
     200        $script .= "    function scanForBrokenImages() {\n";
     201        $script .= "        var imgs = document.querySelectorAll('img');\n";
     202        $script .= "        for (var i = 0; i < imgs.length; i++) {\n";
     203        $script .= "            var img = imgs[i];\n";
     204        $script .= "            if (img.getAttribute('data-sd-fallback') === 'done') continue;\n";
     205        $script .= "            var src = img.currentSrc || img.src;\n";
     206        $script .= "            // If it's a CDN image AND it has 0 natural width (broken), force fix it\n";
     207        $script .= "            if (src && src.indexOf('cdn.staticdelivr.com') > -1) {\n";
     208        $script .= "                // If complete but 0 width (broken), fix it\n";
     209        $script .= "                if (img.complete && img.naturalWidth === 0) {\n";
     210        $script .= "                    log('Sweeper found silent failure:', src);\n";
     211        $script .= "                    var original = img.getAttribute('data-original-src') || extractOriginalFromCdnUrl(src);\n";
     212        $script .= "                    if (original) performFallback(img, original, src);\n";
     213        $script .= "                }\n";
    226214        $script .= "            }\n";
    227         $script .= "            log('Script fallback complete:', original);\n";
    228         $script .= "\n";
    229         $script .= "        } else if (tagName === 'LINK') {\n";
    230         $script .= "            el.href = original;\n";
    231         $script .= "            log('Stylesheet fallback complete:', original);\n";
    232         $script .= "\n";
    233         $script .= "        } else if (tagName === 'IMG') {\n";
    234         $script .= "            // Handle srcset first\n";
    235         $script .= "            if (el.srcset) {\n";
    236         $script .= "                var newSrcset = el.srcset.split(',').map(function(entry) {\n";
    237         $script .= "                    var parts = entry.trim().split(/\\s+/);\n";
    238         $script .= "                    var url = parts[0];\n";
    239         $script .= "                    var descriptor = parts.slice(1).join(' ');\n";
    240         $script .= "                    var extracted = extractOriginalFromCdnUrl(url);\n";
    241         $script .= "                    if (extracted) url = extracted;\n";
    242         $script .= "                    return descriptor ? url + ' ' + descriptor : url;\n";
    243         $script .= "                }).join(', ');\n";
    244         $script .= "                el.srcset = newSrcset;\n";
    245         $script .= "            }\n";
    246         $script .= "            el.src = original;\n";
    247         $script .= "            log('Image fallback complete:', original);\n";
    248215        $script .= "        }\n";
    249216        $script .= "    }\n";
    250217        $script .= "\n";
    251         $script .= "    // Capture errors in capture phase\n";
    252218        $script .= "    window.addEventListener('error', handleError, true);\n";
    253         $script .= "\n";
     219        $script .= "    window.addEventListener('load', function() { setTimeout(scanForBrokenImages, 2500); });\n"; // Run after lazy load might have failed
    254220        $script .= "    log('Fallback script initialized (v%s)');\n";
    255221        $script .= '})();';
  • staticdelivr/tags/2.4.1/staticdelivr.php

    r3447061 r3447066  
    33 * Plugin Name: StaticDelivr CDN
    44 * Description: Speed up your WordPress site with free CDN delivery and automatic image optimization. Reduces load times and bandwidth costs.
    5  * Version: 2.4.0
     5 * Version: 2.4.1
    66 * Requires at least: 5.8
    77 * Requires PHP: 7.4
     
    2121// Define plugin constants.
    2222if (!defined('STATICDELIVR_VERSION')) {
    23     define('STATICDELIVR_VERSION', '2.4.0');
     23    define('STATICDELIVR_VERSION', '2.4.1');
    2424}
    2525if (!defined('STATICDELIVR_PLUGIN_FILE')) {
  • staticdelivr/trunk/README.txt

    r3447061 r3447066  
    66Tested up to: 6.9
    77Requires PHP: 7.4
    8 Stable tag: 2.3.0
     8Stable tag: 2.4.1
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    240240== Changelog ==
    241241
     242= 2.4.1 =
     243* Fixed: Resolved an issue where lazy-loaded images could fail silently without triggering the fallback mechanism (Browser Intervention).
     244* Improved: Fallback script now aggressively removes `srcset` and `loading` attributes to force browsers to retry failed images immediately.
     245* New: Added a "Sweeper" function to automatically detect and repair broken images that were missed by standard error listeners.
     246* Fixed: Improved error detection logic to prioritize `currentSrc`, ensuring failures in responsive thumbnails are caught even if the main src is valid.
     247
    242248= 2.4.0 =
    243249* New: Smart Dimension Detection. The plugin now automatically identifies missing width and height attributes for WordPress images and restores them using attachment metadata.
     
    403409== Upgrade Notice ==
    404410
     411= 2.4.1 =
     412Critical fix for images failing to load on modern browsers. This update handles "Lazy Load Interventions" and ensures the fallback mechanism works 100% of the time. Recommended for all users.
     413
    405414= 2.4.0 =
    406415This update introduces Smart Dimension Detection to automatically fix PageSpeed Insights warnings and improve your site's SEO and CLS scores. Highly recommended for all users.
  • staticdelivr/trunk/includes/class-staticdelivr-fallback.php

    r3446519 r3447066  
    108108        $ajax_url = admin_url( 'admin-ajax.php' );
    109109        $nonce    = wp_create_nonce( 'staticdelivr_failure_report' );
    110 
    111110        $debug_enabled = get_option( STATICDELIVR_PREFIX . 'debug_mode', false ) ? 'true' : 'false';
    112111
     
    116115        $script .= "    var SD_NONCE = '%s';\n";
    117116        $script .= "\n";
    118         $script .= "    function log() {\n";
    119         $script .= "        if (SD_DEBUG && console && console.log) {\n";
    120         $script .= "            console.log.apply(console, ['[StaticDelivr]'].concat(Array.prototype.slice.call(arguments)));\n";
    121         $script .= "        }\n";
    122         $script .= "    }\n";
     117        $script .= "    function log() { if (SD_DEBUG && console) console.log.apply(console, ['[StaticDelivr]'].concat(Array.prototype.slice.call(arguments))); }\n";
    123118        $script .= "\n";
    124119        $script .= "    function reportFailure(type, url, original) {\n";
     
    130125        $script .= "            data.append('url', url);\n";
    131126        $script .= "            data.append('original', original || '');\n";
    132         $script .= "\n";
    133         $script .= "            if (navigator.sendBeacon) {\n";
    134         $script .= "                navigator.sendBeacon(SD_AJAX_URL, data);\n";
    135         $script .= "            } else {\n";
    136         $script .= "                var xhr = new XMLHttpRequest();\n";
    137         $script .= "                xhr.open('POST', SD_AJAX_URL, true);\n";
    138         $script .= "                xhr.send(data);\n";
    139         $script .= "            }\n";
     127        $script .= "            if (navigator.sendBeacon) navigator.sendBeacon(SD_AJAX_URL, data);\n";
     128        $script .= "            else { var xhr = new XMLHttpRequest(); xhr.open('POST', SD_AJAX_URL, true); xhr.send(data); }\n";
    140129        $script .= "            log('Reported failure:', type, url);\n";
    141         $script .= "        } catch(e) {\n";
    142         $script .= "            log('Failed to report:', e);\n";
    143         $script .= "        }\n";
     130        $script .= "        } catch(e) { log('Failed to report:', e); }\n";
    144131        $script .= "    }\n";
    145132        $script .= "\n";
     
    150137        $script .= "            if (!attr || !attr.name) continue;\n";
    151138        $script .= "            if (attr.name === 'src' || attr.name === 'href' || attr.name === 'data-original-src' || attr.name === 'data-original-href') continue;\n";
    152         $script .= "            try {\n";
    153         $script .= "                to.setAttribute(attr.name, attr.value);\n";
    154         $script .= "            } catch(e) {}\n";
     139        $script .= "            try { to.setAttribute(attr.name, attr.value); } catch(e) {}\n";
    155140        $script .= "        }\n";
    156141        $script .= "    }\n";
     
    161146        $script .= "        try {\n";
    162147        $script .= "            var urlObj = new URL(cdnUrl);\n";
    163         $script .= "            var originalUrl = urlObj.searchParams.get('url');\n";
    164         $script .= "            if (originalUrl) {\n";
    165         $script .= "                log('Extracted original URL from query param:', originalUrl);\n";
    166         $script .= "                return originalUrl;\n";
    167         $script .= "            }\n";
    168         $script .= "        } catch(e) {\n";
    169         $script .= "            log('Failed to parse CDN URL:', cdnUrl, e);\n";
    170         $script .= "        }\n";
    171         $script .= "        return null;\n";
     148        $script .= "            return urlObj.searchParams.get('url');\n";
     149        $script .= "        } catch(e) { return null; }\n";
     150        $script .= "    }\n";
     151        $script .= "\n";
     152        $script .= "    // --- CORE FIXER LOGIC ---\n";
     153        $script .= "    function performFallback(el, original, failedUrl) {\n";
     154        $script .= "        if (el.getAttribute('data-sd-fallback') === 'done') return;\n";
     155        $script .= "        el.setAttribute('data-sd-fallback', 'done');\n";
     156        $script .= "        log('Forcing fallback on:', original);\n";
     157        $script .= "\n";
     158        $script .= "        // CRITICAL: Remove srcset/loading to bypass browser interventions\n";
     159        $script .= "        el.removeAttribute('srcset');\n";
     160        $script .= "        el.removeAttribute('sizes');\n";
     161        $script .= "        el.removeAttribute('loading');\n";
     162        $script .= "        el.src = original;\n";
     163        $script .= "\n";
     164        $script .= "        if (failedUrl) reportFailure('image', failedUrl, original);\n";
    172165        $script .= "    }\n";
    173166        $script .= "\n";
     
    179172        $script .= "        if (!tagName) return;\n";
    180173        $script .= "\n";
    181         $script .= "        // Only handle elements we care about\n";
    182         $script .= "        if (tagName !== 'SCRIPT' && tagName !== 'LINK' && tagName !== 'IMG') return;\n";
    183         $script .= "\n";
    184         $script .= "        // Get the failed URL\n";
    185         $script .= "        var failedUrl = '';\n";
    186         $script .= "        if (tagName === 'IMG') failedUrl = el.src || el.currentSrc || '';\n";
    187         $script .= "        else if (tagName === 'SCRIPT') failedUrl = el.src || '';\n";
    188         $script .= "        else if (tagName === 'LINK') failedUrl = el.href || '';\n";
    189         $script .= "\n";
    190         $script .= "        // Only handle StaticDelivr URLs\n";
    191         $script .= "        if (failedUrl.indexOf('cdn.staticdelivr.com') === -1) return;\n";
     174        $script .= "        var failedUrl = (tagName === 'IMG') ? (el.currentSrc || el.src) : (el.href || el.src);\n";
     175        $script .= "        if (!failedUrl || failedUrl.indexOf('cdn.staticdelivr.com') === -1) return;\n";
    192176        $script .= "\n";
    193177        $script .= "        log('Caught error on:', tagName, failedUrl);\n";
    194178        $script .= "\n";
    195         $script .= "        // Prevent double-processing\n";
    196         $script .= "        if (el.getAttribute && el.getAttribute('data-sd-fallback') === 'done') return;\n";
    197         $script .= "\n";
    198         $script .= "        // Get original URL\n";
    199179        $script .= "        var original = el.getAttribute('data-original-src') || el.getAttribute('data-original-href');\n";
    200180        $script .= "        if (!original) original = extractOriginalFromCdnUrl(failedUrl);\n";
    201         $script .= "\n";
    202         $script .= "        if (!original) {\n";
    203         $script .= "            log('Could not determine original URL for:', failedUrl);\n";
    204         $script .= "            return;\n";
    205         $script .= "        }\n";
    206         $script .= "\n";
    207         $script .= "        el.setAttribute('data-sd-fallback', 'done');\n";
    208         $script .= "        log('Falling back to origin:', tagName, original);\n";
    209         $script .= "\n";
    210         $script .= "        // Report the failure\n";
    211         $script .= "        var reportType = (tagName === 'IMG') ? 'image' : 'asset';\n";
    212         $script .= "        reportFailure(reportType, failedUrl, original);\n";
    213         $script .= "\n";
    214         $script .= "        if (tagName === 'SCRIPT') {\n";
     181        $script .= "        if (!original) return;\n";
     182        $script .= "\n";
     183        $script .= "        if (tagName === 'IMG') {\n";
     184        $script .= "            performFallback(el, original, failedUrl);\n";
     185        $script .= "        } else if (tagName === 'SCRIPT') {\n";
     186        $script .= "            el.setAttribute('data-sd-fallback', 'done');\n";
     187        $script .= "            reportFailure('asset', failedUrl, original);\n";
    215188        $script .= "            var newScript = document.createElement('script');\n";
    216189        $script .= "            newScript.src = original;\n";
    217         $script .= "            newScript.async = el.async;\n";
    218         $script .= "            newScript.defer = el.defer;\n";
    219         $script .= "            if (el.type) newScript.type = el.type;\n";
    220         $script .= "            if (el.noModule) newScript.noModule = true;\n";
    221         $script .= "            if (el.crossOrigin) newScript.crossOrigin = el.crossOrigin;\n";
    222190        $script .= "            copyAttributes(el, newScript);\n";
    223         $script .= "            if (el.parentNode) {\n";
    224         $script .= "                el.parentNode.insertBefore(newScript, el.nextSibling);\n";
    225         $script .= "                el.parentNode.removeChild(el);\n";
     191        $script .= "            if(el.parentNode) { el.parentNode.insertBefore(newScript, el.nextSibling); el.parentNode.removeChild(el); }\n";
     192        $script .= "        } else if (tagName === 'LINK') {\n";
     193        $script .= "            el.setAttribute('data-sd-fallback', 'done');\n";
     194        $script .= "            reportFailure('asset', failedUrl, original);\n";
     195        $script .= "            el.href = original;\n";
     196        $script .= "        }\n";
     197        $script .= "    }\n";
     198        $script .= "\n";
     199        $script .= "    // --- THE SWEEPER (Catches silent failures) ---\n";
     200        $script .= "    function scanForBrokenImages() {\n";
     201        $script .= "        var imgs = document.querySelectorAll('img');\n";
     202        $script .= "        for (var i = 0; i < imgs.length; i++) {\n";
     203        $script .= "            var img = imgs[i];\n";
     204        $script .= "            if (img.getAttribute('data-sd-fallback') === 'done') continue;\n";
     205        $script .= "            var src = img.currentSrc || img.src;\n";
     206        $script .= "            // If it's a CDN image AND it has 0 natural width (broken), force fix it\n";
     207        $script .= "            if (src && src.indexOf('cdn.staticdelivr.com') > -1) {\n";
     208        $script .= "                // If complete but 0 width (broken), fix it\n";
     209        $script .= "                if (img.complete && img.naturalWidth === 0) {\n";
     210        $script .= "                    log('Sweeper found silent failure:', src);\n";
     211        $script .= "                    var original = img.getAttribute('data-original-src') || extractOriginalFromCdnUrl(src);\n";
     212        $script .= "                    if (original) performFallback(img, original, src);\n";
     213        $script .= "                }\n";
    226214        $script .= "            }\n";
    227         $script .= "            log('Script fallback complete:', original);\n";
    228         $script .= "\n";
    229         $script .= "        } else if (tagName === 'LINK') {\n";
    230         $script .= "            el.href = original;\n";
    231         $script .= "            log('Stylesheet fallback complete:', original);\n";
    232         $script .= "\n";
    233         $script .= "        } else if (tagName === 'IMG') {\n";
    234         $script .= "            // Handle srcset first\n";
    235         $script .= "            if (el.srcset) {\n";
    236         $script .= "                var newSrcset = el.srcset.split(',').map(function(entry) {\n";
    237         $script .= "                    var parts = entry.trim().split(/\\s+/);\n";
    238         $script .= "                    var url = parts[0];\n";
    239         $script .= "                    var descriptor = parts.slice(1).join(' ');\n";
    240         $script .= "                    var extracted = extractOriginalFromCdnUrl(url);\n";
    241         $script .= "                    if (extracted) url = extracted;\n";
    242         $script .= "                    return descriptor ? url + ' ' + descriptor : url;\n";
    243         $script .= "                }).join(', ');\n";
    244         $script .= "                el.srcset = newSrcset;\n";
    245         $script .= "            }\n";
    246         $script .= "            el.src = original;\n";
    247         $script .= "            log('Image fallback complete:', original);\n";
    248215        $script .= "        }\n";
    249216        $script .= "    }\n";
    250217        $script .= "\n";
    251         $script .= "    // Capture errors in capture phase\n";
    252218        $script .= "    window.addEventListener('error', handleError, true);\n";
    253         $script .= "\n";
     219        $script .= "    window.addEventListener('load', function() { setTimeout(scanForBrokenImages, 2500); });\n"; // Run after lazy load might have failed
    254220        $script .= "    log('Fallback script initialized (v%s)');\n";
    255221        $script .= '})();';
  • staticdelivr/trunk/staticdelivr.php

    r3447061 r3447066  
    33 * Plugin Name: StaticDelivr CDN
    44 * Description: Speed up your WordPress site with free CDN delivery and automatic image optimization. Reduces load times and bandwidth costs.
    5  * Version: 2.4.0
     5 * Version: 2.4.1
    66 * Requires at least: 5.8
    77 * Requires PHP: 7.4
     
    2121// Define plugin constants.
    2222if (!defined('STATICDELIVR_VERSION')) {
    23     define('STATICDELIVR_VERSION', '2.4.0');
     23    define('STATICDELIVR_VERSION', '2.4.1');
    2424}
    2525if (!defined('STATICDELIVR_PLUGIN_FILE')) {
Note: See TracChangeset for help on using the changeset viewer.