Plugin Directory

Changeset 3801444


Ignore:
Timestamp:
11/14/2026 06:07:36 AM (4 days ago)
Author:
imzura
Message:

Release 1.6.0

Location:
imzura-site-check
Files:
8 added
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • imzura-site-check/tags/1.6.0/assets/admin.js

    r3797865 r3801444  
    2121        let tidy = data.tidy || null;
    2222        let tidyNote = '';
     23        let spare = data.spare || null;
     24        let spareNote = '';
    2325        let lastReport = data.report;
    2426        let busy = false;
    … …  
    153155                                const fix = finding.fix && fixes.find( ( item ) => item.id === finding.fix );
    154156
    155                                 if ( finding.fix === 'tidy:revisions' && tidy ) {
     157                                if ( finding.id === 'autoload' && ( spare || spareNote || finding.fix === 'tidy:autoload' ) ) {
     158                                        card.append( spareBlock( finding.fix === 'tidy:autoload' ) );
     159                                } else if ( finding.fix === 'tidy:revisions' && tidy ) {
    156160                                        card.append( el( 'p', '', text.tidy_card ) );
    157161                                } else if ( finding.fix === 'tidy:revisions' ) {
    … …  
    250254                        const targets = started.targets;
    251255                        const pages = {};
    252                         const busy = {};
     256                        const frames = {};
    253257                        let reading = '';
    254258                        let watcher = null;
    255259
     260                        function take( entries ) {
     261                                entries.forEach( ( entry ) => {
     262                                        if ( reading ) {
     263                                                frames[ reading ].push( {
     264                                                        at: performance.timeOrigin + entry.startTime,
     265                                                        scripts: ( entry.scripts || [] ).filter( ( script ) => script.windowAttribution === 'descendant' ).map( ( script ) => ( { url: String( script.sourceURL || '' ).split( /[?#]/ )[ 0 ], ms: script.duration } ) ),
     266                                                } );
     267                                        }
     268                                } );
     269                        }
     270
     271                        function costs( list, keep, limit ) {
     272                                const found = {};
     273
     274                                list.forEach( ( item ) => {
     275                                        if ( keep( item ) ) {
     276                                                item.scripts.forEach( ( script ) => {
     277                                                        if ( script.url ) {
     278                                                                found[ script.url ] = ( found[ script.url ] || 0 ) + script.ms;
     279                                                        }
     280                                                } );
     281                                        }
     282                                } );
     283
     284                                return Object.keys( found ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( found[ url ] ) } ) ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, limit );
     285                        }
     286
     287                        function measured( list, poke ) {
     288                                const cut = poke && poke.from ? poke.from : Infinity;
     289                                const quiet = poke && poke.idle ? poke.idle : null;
     290                                const taps = poke && Array.isArray( poke.taps ) ? poke.taps : [];
     291
     292                                return {
     293                                        busy: costs( list, ( item ) => item.at < cut, 20 ),
     294                                        idle: quiet ? costs( list, ( item ) => item.at >= quiet.from && item.at < quiet.to, 10 ) : [],
     295                                        taps: taps.slice( 0, 8 ).map( ( tap ) => ( {
     296                                                what: String( tap.what || '' ).slice( 0, 80 ),
     297                                                ms: Math.round( tap.ms ) || 0,
     298                                                handled: Math.round( tap.handled ) || 0,
     299                                                scripts: ( Array.isArray( tap.scripts ) ? tap.scripts : [] ).slice( 0, 5 ),
     300                                        } ) ),
     301                                        nodes: poke && poke.nodes ? poke.nodes : 0,
     302                                };
     303                        }
     304
    256305                        try {
    257                                 watcher = new PerformanceObserver( ( list ) => list.getEntries().forEach( ( entry ) => ( entry.scripts || [] ).forEach( ( script ) => {
    258                                         const url = String( script.sourceURL || '' ).split( /[?#]/ )[ 0 ];
    259 
    260                                         if ( reading && url && script.windowAttribution === 'descendant' ) {
    261                                                 busy[ reading ][ url ] = ( busy[ reading ][ url ] || 0 ) + script.duration;
    262                                         }
    263                                 } ) ) );
     306                                watcher = new PerformanceObserver( ( list ) => take( list.getEntries() ) );
    264307                                watcher.observe( { type: 'long-animation-frame' } );
    265308                        } catch ( error ) {
    … …  
    272315                                meter.value = i;
    273316                                reading = targets[ i ].kind;
    274                                 busy[ reading ] = {};
     317                                frames[ reading ] = [];
    275318
    276319                                const seen = await open( Object.assign( { screen: 'phone', scan: true }, targets[ i ] ) );
    277320
     321                                if ( watcher ) {
     322                                        take( watcher.takeRecords() );
     323                                }
     324
    278325                                if ( seen ) {
    279                                         pages[ reading ] = { errors: seen.errors, sources: seen.sources, look: Object.assign( {}, seen.look, { busy: Object.keys( busy[ reading ] ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( busy[ reading ][ url ] ) } ) ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, 20 ) } ) };
     326                                        pages[ reading ] = { errors: seen.errors, sources: seen.sources, look: Object.assign( {}, seen.look, measured( frames[ reading ], seen.taps ) ) };
    280327                                }
    281328                        }
    … …  
    608655        }
    609656
     657        function spareBlock( offer ) {
     658                const box = el( 'div', 'speed-doctor-spare' );
     659                const actions = el( 'div', 'speed-doctor-actions imz-actions' );
     660
     661                if ( spareNote ) {
     662                        box.append( el( 'p', '', spareNote ) );
     663                }
     664
     665                if ( offer ) {
     666                        actions.append( spareButton( text.spare_go, 'run', true ) );
     667                }
     668
     669                if ( spare ) {
     670                        box.append( el( 'p', '', fill( text.spare_done, [ spare.count.toLocaleString(), size( spare.bytes ), new Date( spare.time * 1000 ).toLocaleString() ] ) ) );
     671                        actions.append( spareButton( text.spare_undo, 'undo', false ) );
     672                }
     673
     674                if ( actions.childNodes.length ) {
     675                        box.append( actions );
     676                }
     677
     678                return box;
     679        }
     680
     681        function spareButton( label, step, primary ) {
     682                const go = el( 'button', primary ? 'button button-primary imz-btn imz-btn--primary' : 'button imz-btn', label );
     683                go.type = 'button';
     684                go.disabled = busy;
     685                go.addEventListener( 'click', () => spareStep( step ) );
     686                return go;
     687        }
     688
     689        async function spareStep( step ) {
     690                if ( busy ) {
     691                        return;
     692                }
     693
     694                busy = true;
     695                spareNote = '';
     696
     697                try {
     698                        const answer = ( await call( '/tidy/autoload/' + step, 'POST' ) ).autoload;
     699
     700                        if ( step === 'run' ) {
     701                                spare = answer;
     702                                ( lastReport ? lastReport.findings : [] ).forEach( ( finding ) => {
     703                                        if ( finding.id === 'autoload' ) {
     704                                                finding.fix = '';
     705                                        }
     706                                } );
     707                        } else {
     708                                spare = null;
     709                                spareNote = fill( text.spare_back, [ answer.restored.toLocaleString() ] );
     710                        }
     711                } catch ( error ) {
     712                        spareNote = error.reason || text.spare_failed;
     713                }
     714
     715                busy = false;
     716                refresh();
     717        }
     718
    610719        function tidyButton( label, step, primary ) {
    611720                const go = el( 'button', primary ? 'button button-primary imz-btn imz-btn--primary' : 'button imz-btn', label );
    … …  
    703812                        const frame = el( 'iframe', 'speed-doctor-frame' + ( load.screen === 'phone' ? ' is-phone' : '' ) + ( load.scan ? ' is-scan' : '' ) );
    704813                        let timer = 0;
     814                        let got = null;
    705815
    706816                        function finish( report ) {
    … …  
    712822
    713823                        function hear( event ) {
    714                                 if ( event.source === frame.contentWindow && event.data && event.data.speedDoctor === load.token ) {
     824                                if ( event.source !== frame.contentWindow || ! event.data || event.data.speedDoctor !== load.token ) {
     825                                        return;
     826                                }
     827
     828                                if ( got ) {
     829                                        if ( event.data.taps ) {
     830                                                got.taps = event.data.taps;
     831                                                finish( got );
     832                                        }
     833                                } else if ( event.data.report && load.scan && ! load.admin ) {
     834                                        got = event.data.report;
     835                                        clearTimeout( timer );
     836                                        timer = setTimeout( () => finish( got ), 15000 );
     837                                } else if ( event.data.report ) {
    715838                                        finish( event.data.report );
    716839                                }
    … …  
    724847
    725848                        frame.addEventListener( 'load', () => {
     849                                if ( got ) {
     850                                        return;
     851                                }
     852
    726853                                clearTimeout( timer );
    727854                                timer = setTimeout( () => finish( null ), load.admin ? 300 : 20000 );
    … …  
    10071134                        refresh();
    10081135                        say( fix, error.reason || text.trial_failed );
    1009                 }
     1136
     1137                        return error.reason || '';
     1138                }
     1139
     1140                return '';
    10101141        }
    10111142
    … …  
    10461177                trial: async ( id ) => {
    10471178                        const fix = fixes.find( ( item ) => item.id === id );
     1179                        let refused = '';
    10481180
    10491181                        if ( fix && ! busy ) {
    1050                                 await trial( fix );
    1051                         }
    1052 
    1053                         return fixes.find( ( item ) => item.id === id ) || null;
     1182                                refused = await trial( fix );
     1183                        }
     1184
     1185                        const found = fixes.find( ( item ) => item.id === id );
     1186
     1187                        return found && refused ? Object.assign( {}, found, { refused: refused } ) : found || null;
    10541188                },
    10551189                tidy: async ( step ) => {
  • imzura-site-check/tags/1.6.0/assets/probe.js

    r3797416 r3801444  
    1212        let pending = 0;
    1313        let fresh = true;
     14        let poking = false;
    1415
    1516        const listen = EventTarget.prototype.addEventListener;
     17        const unlisten = EventTarget.prototype.removeEventListener;
    1618        const told = new WeakMap();
    17 
    18         EventTarget.prototype.addEventListener = function ( type ) {
     19        const KINDS = /^(click|pointerdown|pointerup|mousedown|mouseup|touchstart|touchend)$/;
     20        const timed = new WeakMap();
     21        const nest = [];
     22        let ledger = null;
     23
     24        function origin( stack ) {
     25                const lines = String( stack || '' ).match( /https?:\/\/[^\s()'"@]+?:\d+:\d+/g ) || [];
     26
     27                for ( let i = 1; i < lines.length; i++ ) {
     28                        const url = lines[ i ].replace( /:\d+:\d+$/, '' ).split( /[?#]/ )[ 0 ];
     29
     30                        if ( ! /\/jquery(-migrate)?(-\d[\w.]*)?(\.min)?\.js$/.test( url ) ) {
     31                                return url;
     32                        }
     33                }
     34
     35                return '';
     36        }
     37
     38        function stopwatch( listener, from ) {
     39                const run = function () {
     40                        const began = performance.now();
     41
     42                        nest.push( 0 );
     43
     44                        try {
     45                                return typeof listener === 'function' ? listener.apply( this, arguments ) : listener.handleEvent.apply( listener, arguments );
     46                        } finally {
     47                                const total = performance.now() - began;
     48                                const inner = nest.pop();
     49
     50                                if ( nest.length ) {
     51                                        nest[ nest.length - 1 ] += total;
     52                                }
     53
     54                                if ( ledger ) {
     55                                        ledger[ from ] = ( ledger[ from ] || 0 ) + total - inner;
     56                                }
     57                        }
     58                };
     59
     60                run.speedDoctor = true;
     61
     62                return run;
     63        }
     64
     65        function watched( type, listener ) {
     66                return probe.tap && listener && ! listener.speedDoctor && KINDS.test( String( type ) ) && ( typeof listener === 'function' || typeof listener.handleEvent === 'function' );
     67        }
     68
     69        EventTarget.prototype.addEventListener = function ( type, listener ) {
    1970                if ( this instanceof Element && heard.length < 5000 ) {
    2071                        const kinds = told.get( this ) || new Set();
    … …  
    2677                }
    2778
     79                if ( watched( type, listener ) ) {
     80                        try {
     81                                if ( ! timed.has( listener ) ) {
     82                                        timed.set( listener, stopwatch( listener, origin( new Error().stack ) ) );
     83                                }
     84
     85                                const args = Array.prototype.slice.call( arguments );
     86                                args[ 1 ] = timed.get( listener );
     87
     88                                return listen.apply( this, args );
     89                        } catch ( error ) {
     90                        }
     91                }
     92
    2893                return listen.apply( this, arguments );
    2994        };
     95
     96        if ( probe.tap ) {
     97                EventTarget.prototype.removeEventListener = function ( type, listener ) {
     98                        if ( listener && KINDS.test( String( type ) ) && timed.has( listener ) ) {
     99                                const args = Array.prototype.slice.call( arguments );
     100                                args[ 1 ] = timed.get( listener );
     101
     102                                return unlisten.apply( this, args );
     103                        }
     104
     105                        return unlisten.apply( this, arguments );
     106                };
     107
     108                const hook = ( jq ) => {
     109                        try {
     110                                if ( ! jq || ! jq.event || typeof jq.event.add !== 'function' || jq.event.add.speedDoctor ) {
     111                                        return;
     112                                }
     113
     114                                const add = jq.event.add;
     115
     116                                jq.event.add = function ( elem, types, handler ) {
     117                                        try {
     118                                                const fn = handler && handler.handler ? handler.handler : handler;
     119
     120                                                if ( typeof types === 'string' && typeof fn === 'function' && ! fn.speedDoctor && /(^|\s)(click|pointerdown|pointerup|mousedown|mouseup|touchstart|touchend)(\.|\s|$)/.test( types ) ) {
     121                                                        if ( ! fn.guid ) {
     122                                                                fn.guid = jq.guid++;
     123                                                        }
     124
     125                                                        const run = stopwatch( fn, origin( new Error().stack ) );
     126                                                        const args = Array.prototype.slice.call( arguments );
     127
     128                                                        run.guid = fn.guid;
     129                                                        args[ 2 ] = handler && handler.handler ? Object.assign( {}, handler, { handler: run } ) : run;
     130
     131                                                        return add.apply( this, args );
     132                                                }
     133                                        } catch ( error ) {
     134                                        }
     135
     136                                        return add.apply( this, arguments );
     137                                };
     138
     139                                jq.event.add.speedDoctor = true;
     140                        } catch ( error ) {
     141                        }
     142                };
     143
     144                let held = window.jQuery;
     145
     146                hook( held );
     147
     148                try {
     149                        Object.defineProperty( window, 'jQuery', {
     150                                configurable: true,
     151                                enumerable: true,
     152                                get: () => held,
     153                                set: ( value ) => {
     154                                        held = value;
     155                                        hook( value );
     156                                },
     157                        } );
     158                } catch ( error ) {
     159                }
     160        }
    30161
    31162        function memory() {
    … …  
    67198        };
    68199
    69         const painted = { lcp: null, shift: 0, shifters: [] };
     200        const painted = { lcp: null, shift: 0, shifters: [], pushers: [] };
     201        const added = [];
    70202
    71203        function observe( type, take ) {
    … …  
    84216        }
    85217
     218        if ( probe.scan && window.MutationObserver ) {
     219                new MutationObserver( ( list ) => {
     220                        const at = performance.now();
     221
     222                        while ( added.length && added[ 0 ][ 0 ] < at - 3000 ) {
     223                                added.shift();
     224                        }
     225
     226                        list.forEach( ( change ) => change.addedNodes.forEach( ( node ) => {
     227                                if ( 1 === node.nodeType && added.length < 400 && ! /^(SCRIPT|STYLE|LINK|META|NOSCRIPT|TEMPLATE|BR)$/.test( node.nodeName ) ) {
     228                                        added.push( [ at, node ] );
     229                                }
     230                        } ) );
     231                } ).observe( document.documentElement, { childList: true, subtree: true } );
     232        }
     233
     234        function pusher( entry ) {
     235                let top = Infinity;
     236                let best = null;
     237                let tallest = 0;
     238
     239                ( entry.sources || [] ).forEach( ( source ) => {
     240                        top = Math.min( top, source.previousRect ? source.previousRect.top : Infinity );
     241                } );
     242
     243                added.forEach( ( item ) => {
     244                        const node = item[ 1 ];
     245
     246                        if ( item[ 0 ] > entry.startTime || item[ 0 ] < entry.startTime - 1000 || ! node.isConnected ) {
     247                                return;
     248                        }
     249
     250                        if ( ( entry.sources || [] ).some( ( source ) => source.node && ( node === source.node || node.contains( source.node ) ) ) ) {
     251                                return;
     252                        }
     253
     254                        const box = node.getBoundingClientRect();
     255
     256                        if ( box.height > tallest && box.width > 0 && box.top <= top + 1 ) {
     257                                tallest = box.height;
     258                                best = node;
     259                        }
     260                } );
     261
     262                return best;
     263        }
     264
    86265        if ( probe.scan && window.PerformanceObserver ) {
    87266                observe( 'layout-shift', ( entry ) => {
    88267                        if ( ! entry.hadRecentInput ) {
     268                                const cause = pusher( entry );
     269
    89270                                painted.shift += entry.value;
    90271                                ( entry.sources || [] ).forEach( ( source ) => source.node && painted.shifters.push( [ entry.value, source.node ] ) );
     272
     273                                if ( cause ) {
     274                                        painted.pushers.push( [ entry.value, cause ] );
     275                                }
    91276                        }
    92277                } );
    … …  
    94279
    95280        function note( kind, detail, file ) {
     281                if ( poking ) {
     282                        return;
     283                }
     284
    96285                const said = String( detail ).replace( /^Uncaught\s+/, '' ).replace( /^\(in promise\)\s+/, '' ).replace( /^[A-Za-z]*Error:\s+/, '' );
    97286                const key = kind + ': ' + said.slice( 0, 160 );
    … …  
    147336                const started = performance.now();
    148337
     338                if ( poking ) {
     339                        return;
     340                }
     341
    149342                if ( own( request.speedDoctorUrl ) ) {
    150343                        try {
    … …  
    166359                        const url = typeof input === 'string' ? input : ( input && input.url ) || String( input );
    167360                        const started = performance.now();
     361
     362                        if ( poking ) {
     363                                return new Promise( () => {} );
     364                        }
    168365
    169366                        if ( own( url ) ) {
    … …  
    186383                        );
    187384                };
     385        }
     386
     387        if ( probe.tap ) {
     388                try {
     389                        const beacon = navigator.sendBeacon;
     390                        const popup = window.open;
     391
     392                        if ( beacon ) {
     393                                navigator.sendBeacon = function () {
     394                                        return poking ? true : beacon.apply( navigator, arguments );
     395                                };
     396                        }
     397
     398                        window.open = function () {
     399                                return poking ? null : popup.apply( window, arguments );
     400                        };
     401                } catch ( error ) {
     402                }
     403
     404                [ 'click', 'submit', 'auxclick' ].forEach( ( type ) => listen.call( window, type, ( event ) => poking && event.preventDefault(), true ) );
    188405        }
    189406
    … …  
    554771
    555772                return found;
     773        }
     774
     775        function dom() {
     776                const all = document.body ? document.body.getElementsByTagName( '*' ) : [];
     777                const total = all.length;
     778                const size = new Map();
     779
     780                if ( ! total || total > 60000 ) {
     781                        return { total: total, hidden: 0, parts: [] };
     782                }
     783
     784                for ( let i = total - 1; i >= 0; i-- ) {
     785                        const own = ( size.get( all[ i ] ) || 0 ) + 1;
     786                        const up = all[ i ].parentElement;
     787
     788                        size.set( all[ i ], own );
     789
     790                        if ( up && up !== document.body ) {
     791                                size.set( up, ( size.get( up ) || 0 ) + own );
     792                        }
     793                }
     794
     795                const parts = [];
     796                const big = Array.from( size.keys() ).filter( ( node ) => size.get( node ) >= total * 0.15 ).sort( ( a, b ) => size.get( b ) - size.get( a ) );
     797
     798                for ( let i = 0; i < big.length && parts.length < 3; i++ ) {
     799                        const node = big[ i ];
     800                        const most = Array.prototype.reduce.call( node.children, ( top, child ) => Math.max( top, size.get( child ) || 0 ), 0 );
     801
     802                        if ( most <= size.get( node ) * 0.6 && ! parts.some( ( part ) => part.node.contains( node ) || node.contains( part.node ) ) ) {
     803                                parts.push( { node: node, count: size.get( node ) } );
     804                        }
     805                }
     806
     807                let hidden = 0;
     808                let skip = null;
     809
     810                for ( let i = 0; i < total && i < 20000; i++ ) {
     811                        if ( skip && skip.contains( all[ i ] ) ) {
     812                                continue;
     813                        }
     814
     815                        if ( getComputedStyle( all[ i ] ).display === 'none' ) {
     816                                hidden += size.get( all[ i ] ) || 1;
     817                                skip = all[ i ];
     818                        }
     819                }
     820
     821                return { total: total, hidden: hidden, parts: parts.map( ( part ) => ( { what: describe( part.node ), count: part.count } ) ) };
    556822        }
    557823
    … …  
    611877                        shift: Math.round( painted.shift * 1000 ) / 1000,
    612878                        shifters: painted.shifters.sort( ( a, b ) => b[ 0 ] - a[ 0 ] ).map( ( item ) => describe( item[ 1 ] ) ).filter( ( what, i, all ) => what && all.indexOf( what ) === i ).slice( 0, 3 ),
     879                        pushers: painted.pushers.sort( ( a, b ) => b[ 0 ] - a[ 0 ] ).map( ( item ) => describe( item[ 1 ] ) ).filter( ( what, i, all ) => what && all.indexOf( what ) === i ).slice( 0, 2 ),
    613880                        lazyTop: lazyTop,
    614881                        sizeless: sizeless,
    … …  
    618885                        styles: usage(),
    619886                        links: links(),
     887                        dom: dom(),
    620888                };
     889        }
     890
     891        const RISKY = /(^|[^a-z])(cart|checkout|basket|buy|order|pay|purchase|log-?in|log-?out|sign-?in|sign-?up|register|account|delete|remove|subscribe|submit|wishlist|compare|book|reserv|download|print|share|call|phone|mailto)/i;
     892
     893        function wait( ms ) {
     894                return new Promise( ( resolve ) => setTimeout( resolve, ms ) );
     895        }
     896
     897        function stamp() {
     898                return Math.round( performance.timeOrigin + performance.now() );
     899        }
     900
     901        function tappable( node ) {
     902                if ( node.closest( 'form, [contenteditable="true"], [contenteditable=""]' ) || node.closest( 'a[href]:not([href^="#"])' ) ) {
     903                        return false;
     904                }
     905
     906                if ( node.matches( '[disabled], [aria-disabled="true"], [type="submit"], [type="reset"], [onclick*="location"]' ) ) {
     907                        return false;
     908                }
     909
     910                const words = [ node.id, typeof node.className === 'string' ? node.className : '', node.getAttribute( 'name' ), node.getAttribute( 'href' ), node.getAttribute( 'aria-label' ), ( node.textContent || '' ).slice( 0, 80 ) ].join( ' ' );
     911
     912                if ( RISKY.test( words ) ) {
     913                        return false;
     914                }
     915
     916                const box = node.getBoundingClientRect();
     917
     918                if ( box.width < 8 || box.height < 8 || box.bottom < 0 || box.top > window.innerHeight * 2 ) {
     919                        return false;
     920                }
     921
     922                const style = getComputedStyle( node );
     923
     924                return style.visibility !== 'hidden' && style.pointerEvents !== 'none';
     925        }
     926
     927        function candidates() {
     928                const found = [];
     929                const named = new Set();
     930                const list = document.querySelectorAll( '[aria-expanded], [aria-controls], [aria-haspopup], summary, [role="tab"], button, [role="button"], a[href^="#"]' );
     931
     932                for ( let i = 0; i < list.length && found.length < 5; i++ ) {
     933                        const name = describe( list[ i ] );
     934
     935                        if ( ! named.has( name ) && tappable( list[ i ] ) ) {
     936                                named.add( name );
     937                                found.push( list[ i ] );
     938                        }
     939                }
     940
     941                const middle = document.elementFromPoint( window.innerWidth / 2, Math.min( window.innerHeight / 2, 300 ) );
     942
     943                if ( middle && middle !== document.documentElement && ! middle.closest( 'a, button, input, select, textarea, label, summary, [role="button"], [onclick], form' ) ) {
     944                        found.push( middle );
     945                }
     946
     947                return found;
     948        }
     949
     950        function tap( node ) {
     951                const box = node.getBoundingClientRect();
     952                const at = { bubbles: true, cancelable: true, composed: true, view: window, clientX: box.left + box.width / 2, clientY: box.top + box.height / 2, button: 0 };
     953                const pointer = Object.assign( { pointerId: 1, pointerType: 'touch', isPrimary: true }, at );
     954                const what = describe( node );
     955                const from = stamp();
     956                const started = performance.now();
     957
     958                ledger = {};
     959
     960                [ 'pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click' ].forEach( ( type ) => {
     961                        const touch = type.indexOf( 'pointer' ) === 0 && window.PointerEvent;
     962
     963                        try {
     964                                node.dispatchEvent( touch ? new PointerEvent( type, pointer ) : new MouseEvent( type, at ) );
     965                        } catch ( error ) {
     966                        }
     967                } );
     968
     969                const handled = Math.round( performance.now() - started );
     970                const spent = ledger;
     971
     972                ledger = null;
     973
     974                const scripts = Object.keys( spent ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( spent[ url ] ) } ) ).filter( ( item ) => item.ms > 0 ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, 5 );
     975
     976                return new Promise( ( resolve ) => {
     977                        let done = false;
     978
     979                        function finish() {
     980                                if ( ! done ) {
     981                                        done = true;
     982                                        resolve( { what: what, at: from, handled: handled, ms: Math.round( performance.now() - started ), scripts: scripts } );
     983                                }
     984                        }
     985
     986                        requestAnimationFrame( () => setTimeout( finish, 0 ) );
     987                        setTimeout( finish, 1500 );
     988                } );
     989        }
     990
     991        async function poke() {
     992                poking = true;
     993
     994                const result = { from: stamp(), idle: null, taps: [], nodes: document.getElementsByTagName( '*' ).length };
     995
     996                try {
     997                        const quiet = stamp();
     998
     999                        await wait( 1500 );
     1000                        result.idle = { from: quiet, to: stamp() };
     1001
     1002                        const list = candidates();
     1003
     1004                        for ( let i = 0; i < list.length; i++ ) {
     1005                                if ( list[ i ].isConnected ) {
     1006                                        result.taps.push( await tap( list[ i ] ) );
     1007                                        await wait( 200 );
     1008                                }
     1009                        }
     1010                } catch ( error ) {
     1011                }
     1012
     1013                result.to = stamp();
     1014
     1015                return result;
    6211016        }
    6221017
    … …  
    6591054                                clearInterval( timer );
    6601055                                report();
     1056
     1057                                if ( probe.tap ) {
     1058                                        poke().then( ( taps ) => window.parent.postMessage( { speedDoctor: probe.token, taps: taps }, probe.origin ) );
     1059                                }
    6611060                        }
    6621061                }, 250 );
  • imzura-site-check/tags/1.6.0/imzura-site-check.php

    r3797865 r3801444  
    22/**
    33 * Plugin Name:       imzura Site Check – Speed & Site Optimization
    4  * Plugin URI:        https://imzura.com/products/speed-doctor
     4 * Plugin URI:        https://imzura.com/products/site-check
    55 * Description:       Finds what slows your site down, on the front end, in the admin and in WooCommerce, and proves every fix with a measurement.
    6  * Version:           1.5.0
     6 * Version:           1.6.0
    77 * Requires at least: 6.2
    88 * Requires PHP:      7.4
    … …  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 define( 'SPEED_DOCTOR_VERSION', '1.5.0' );
     20define( 'SPEED_DOCTOR_VERSION', '1.6.0' );
    2121define( 'SPEED_DOCTOR_FILE', __FILE__ );
    2222define( 'SPEED_DOCTOR_DIR', plugin_dir_path( __FILE__ ) );
  • imzura-site-check/tags/1.6.0/includes/checks/class-autoload.php

    r3797325 r3801444  
    55
    66use SpeedDoctor\Check;
     7use SpeedDoctor\Options;
    78
    89defined( 'ABSPATH' ) || exit;
    … …  
    1213        const WARN_KB = 400;
    1314        const HIGH_KB = 800;
     15        const TOP     = 6;
     16
     17        private $admin = array();
     18
     19        public function admin( array $pages ) {
     20                $this->admin = $pages;
     21        }
    1422
    1523        public function run( array $pages ) {
    … …  
    1927                $total = (int) $wpdb->get_var( "SELECT SUM( LENGTH( option_value ) ) FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' )" );
    2028                $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' )" );
    21                 $top   = $wpdb->get_results( "SELECT option_name, LENGTH( option_value ) AS size FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' ) ORDER BY size DESC LIMIT 5" );
    2229                // phpcs:enable
    2330
    24                 $kb = (int) round( $total / 1024 );
     31                $kb    = (int) round( $total / 1024 );
     32                $read  = $this->read( array_merge( $pages, $this->admin ) );
     33                $spare = null === $read || $kb < self::WARN_KB ? array() : Options::spare( $read );
     34
     35                Options::remember( Options::available() ? $spare : array() );
    2536
    2637                if ( $kb < self::WARN_KB ) {
    … …  
    3950                $facts = array();
    4051
    41                 foreach ( (array) $top as $row ) {
    42                         $facts[] = sprintf( '%s — %s', $row->option_name, $this->kb( (int) round( $row->size / 1024 ) ) );
     52                foreach ( array_slice( Options::big(), 0, self::TOP, true ) as $name => $size ) {
     53                        $facts[] = sprintf( '%1$s — %2$s · %3$s', $name, $this->kb( max( 1, (int) round( $size / 1024 ) ) ), $this->owner( Options::owner( $name ) ) );
     54                }
     55
     56                $detail = __( 'This is read from the database before every page and every admin screen, and no page cache can skip it. WordPress\'s Site Health marks more than 800 KB as a problem. The largest entries are listed below with the plugin or theme they belong to.', 'imzura-site-check' );
     57                $fix    = '';
     58
     59                if ( $spare && Options::available() ) {
     60                        $detail .= ' ' . sprintf(
     61                                /* translators: 1: size, 2: number of settings */
     62                                __( '%1$s of it (%2$s entries) belongs to plugins and themes that are not active or were removed, and none of the pages checked read it. The button below stops loading those entries on every request. They stay in the database, so a plugin that comes back still finds its settings, and it can be undone.', 'imzura-site-check' ),
     63                                $this->kb( max( 1, (int) round( array_sum( $spare ) / 1024 ) ) ),
     64                                number_format_i18n( count( $spare ) )
     65                        );
     66                        $fix = 'tidy:autoload';
    4367                }
    4468
    … …  
    5074                                /* translators: 1: size, 2: number of settings */
    5175                                sprintf( __( 'WordPress loads %1$s of settings on every request (%2$s entries)', 'imzura-site-check' ), $this->kb( $kb ), number_format_i18n( $count ) ),
    52                                 __( 'This is read from the database before every page and every admin screen, and no page cache can skip it. Most of it usually belongs to a few plugins, some of them long removed. The largest entries are listed below.', 'imzura-site-check' ),
    53                                 $facts
     76                                $detail,
     77                                $facts,
     78                                $fix
    5479                        ),
    5580                );
    5681        }
     82
     83        private function read( array $pages ) {
     84                $read = null;
     85
     86                foreach ( $pages as $page ) {
     87                        if ( empty( $page['pending'] ) && isset( $page['options'] ) && is_array( $page['options'] ) ) {
     88                                $read = (array) $read + array_fill_keys( array_map( 'strval', $page['options'] ), true );
     89                        }
     90                }
     91
     92                return $read;
     93        }
     94
     95        private function owner( array $owner ) {
     96                if ( 'core' === $owner['kind'] ) {
     97                        return __( 'WordPress', 'imzura-site-check' );
     98                }
     99
     100                if ( 'shared' === $owner['kind'] ) {
     101                        return __( 'temporary data or a library several plugins share', 'imzura-site-check' );
     102                }
     103
     104                if ( 'unknown' === $owner['kind'] ) {
     105                        return __( 'owner not known', 'imzura-site-check' );
     106                }
     107
     108                $name = 'theme' === $owner['kind']
     109                        /* translators: %s: theme name */
     110                        ? sprintf( __( 'the %s theme', 'imzura-site-check' ), $owner['name'] )
     111                        : $owner['name'];
     112
     113                if ( 'inactive' === $owner['state'] ) {
     114                        /* translators: %s: plugin or theme name */
     115                        return sprintf( __( '%s, not active', 'imzura-site-check' ), $name );
     116                }
     117
     118                /* translators: %s: plugin or theme name */
     119                return 'removed' === $owner['state'] ? sprintf( __( '%s, removed', 'imzura-site-check' ), $name ) : $name;
     120        }
    57121}
  • imzura-site-check/tags/1.6.0/includes/checks/class-images.php

    r3797325 r3801444  
    7272                                }
    7373
     74                                $pushed = array();
     75
     76                                foreach ( isset( $look['pushers'] ) && is_array( $look['pushers'] ) ? array_slice( $look['pushers'], 0, 2 ) : array() as $element ) {
     77                                        $pushed[] = self::line( $element, 80 );
     78                                }
     79
    7480                                $shifts[] = array(
    7581                                        'label' => $page['label'],
    7682                                        'shift' => $shift,
    7783                                        'what'  => array_filter( $what ),
     84                                        'by'    => array_filter( $pushed ),
    7885                                );
    7986                        }
    … …  
    164171
    165172                        foreach ( $shifts as $shift ) {
     173                                if ( $shift['by'] ) {
     174                                        /* translators: 1: page name, 2: layout shift score, 3: the elements added while the page loaded, 4: the elements they pushed */
     175                                        $facts[] = sprintf( __( '%1$s: %2$s, %3$s was added while the page loaded and pushed %4$s down', 'imzura-site-check' ), $shift['label'], number_format_i18n( $shift['shift'], 2 ), implode( ', ', $shift['by'] ), $shift['what'] ? implode( ', ', $shift['what'] ) : __( 'the content', 'imzura-site-check' ) );
     176                                        continue;
     177                                }
     178
    166179                                $facts[] = $shift['what']
    167180                                        /* translators: 1: page name, 2: layout shift score, 3: the elements that moved */
  • imzura-site-check/tags/1.6.0/includes/class-admin-page.php

    r3797865 r3801444  
    5555                                'rescue' => esc_url_raw( Fixer::rescue_url() ),
    5656                                'tidy'   => Tidy::state(),
     57                                'spare'  => Options::state(),
    5758                                'review' => array(
    5859                                        'due' => ! get_user_meta( get_current_user_id(), Rest::REVIEW_META, true ),
    … …  
    8687                                        'tidy_forgotten' => __( 'The copy of the old revisions is deleted.', 'imzura-site-check' ),
    8788                                        'tidy_failed'    => __( 'That did not work. Nothing was removed without a copy; reload the page and try again.', 'imzura-site-check' ),
     89                                        'spare_go'       => __( 'Stop loading them on every request', 'imzura-site-check' ),
     90                                        /* translators: 1: number of settings, 2: size, 3: date and time */
     91                                        'spare_done'     => __( '%1$s settings (%2$s) of plugins and themes that are not active no longer load on every request, since %3$s. They are still in the database.', 'imzura-site-check' ),
     92                                        'spare_undo'     => __( 'Load them on every request again', 'imzura-site-check' ),
     93                                        /* translators: %s: number of settings */
     94                                        'spare_back'     => __( '%s settings load on every request again.', 'imzura-site-check' ),
     95                                        'spare_failed'   => __( 'That did not work, and nothing was changed. Reload the page and try again.', 'imzura-site-check' ),
    8896                                        /* translators: %s: a size in megabytes, e.g. 1.4 */
    8997                                        'mb'             => __( '%s MB', 'imzura-site-check' ),
  • imzura-site-check/tags/1.6.0/includes/class-fixer.php

    r3797325 r3801444  
    2424                $fixes = array();
    2525
    26                 foreach ( apply_filters( 'speed_doctor_fixes', array( new Fixes\Cart_Script(), new Fixes\WooCommerce_Files(), new Fixes\Contact_Form_7(), new Fixes\Heavy_Images(), new Fixes\Lcp_Image(), new Fixes\Image_Sizes(), new Fixes\Local_Fonts(), new Fixes\Minify_Styles(), new Fixes\Minify_Scripts(), new Fixes\Emoji(), new Fixes\Visitor_Heartbeat(), new Fixes\Jquery_Migrate(), new Fixes\Defer_Scripts(), new Fixes\Video_Facade() ) ) as $fix ) {
     26                foreach ( apply_filters( 'speed_doctor_fixes', array( new Fixes\Cart_Script(), new Fixes\WooCommerce_Files(), new Fixes\Contact_Form_7(), new Fixes\Heavy_Images(), new Fixes\Lcp_Image(), new Fixes\Image_Sizes(), new Fixes\Local_Fonts(), new Fixes\Minify_Styles(), new Fixes\Minify_Scripts(), new Fixes\Emoji(), new Fixes\Visitor_Heartbeat(), new Fixes\Jquery_Migrate(), new Fixes\Defer_Scripts(), new Fixes\Video_Facade(), new Fixes\Map_Facade() ) ) as $fix ) {
    2727                        if ( $fix instanceof Fix ) {
    2828                                $fixes[ $fix->id() ] = $fix;
  • imzura-site-check/tags/1.6.0/includes/class-plugin.php

    r3797416 r3801444  
    5050                        new Checks\Environment(),
    5151                        new Checks\Delivery(),
     52                        new Checks\Cache_Blockers(),
    5253                        new Checks\Errors(),
    5354                        new Checks\Images(),
    … …  
    5556                        new Checks\Fonts(),
    5657                        new Checks\Scripts(),
     58                        new Checks\Interactions(),
    5759                        new Checks\Idle_Styles(),
    5860                        new Checks\Code_Time(),
  • imzura-site-check/tags/1.6.0/includes/class-probe.php

    r3797325 r3801444  
    2424
    2525        private static $errors = array();
     26
     27        private static $stranger = false;
     28
     29        private static $nocache = false;
    2630
    2731        public static function targets() {
    … …  
    232236                }
    233237
    234                 header_register_callback(
    235                         static function () {
    236                                 header_remove( 'Set-Cookie' );
    237                         }
    238                 );
     238                self::$stranger = true;
     239
     240                header_register_callback( array( __CLASS__, 'sending' ) );
    239241
    240242                // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_seeding_mt_srand -- a fixed seed is the point; it applies to this test request only.
    … …  
    258260                                        'marks'  => isset( self::$trial['marks'] ) ? array_values( (array) self::$trial['marks'] ) : array(),
    259261                                        'scan'   => ! empty( self::$trial['scan'] ),
     262                                        'tap'    => ! empty( self::$trial['tap'] ),
    260263                                )
    261264                        ) . ';' . file_get_contents( SPEED_DOCTOR_DIR . 'assets/probe.js' ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a file of this plugin, only read.
    … …  
    330333        }
    331334
     335        public static function sending() {
     336                Profiler::seal();
     337
     338                if ( self::$stranger ) {
     339                        header_remove( 'Set-Cookie' );
     340                }
     341
     342                if ( self::$nocache ) {
     343                        self::$nocache = false;
     344                        nocache_headers();
     345                }
     346        }
     347
    332348        public static function buffer() {
    333                 nocache_headers();
     349                if ( self::$stranger && Profiler::on() ) {
     350                        self::$nocache = true;
     351                } else {
     352                        nocache_headers();
     353                }
     354
    334355                add_action( 'wp_finalized_template_enhancement_output_buffer', array( __CLASS__, 'keep' ) );
    335356        }
    … …  
    372393                $page['saved']     = Fixer::savings();
    373394                $page['manifest']  = Pipeline::manifest();
     395                $page['cache']     = Profiler::on() && self::$stranger ? Profiler::cache() : null;
     396                $page['options']   = Profiler::options_read();
    374397                $page['context']   = array(
    375398                        'store_page'   => function_exists( 'is_woocommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ),
    … …  
    378401                        'has_store'    => ! $seen || Fixes\WooCommerce_Files::in_page( $html ),
    379402                );
     403
     404                if ( self::$nocache && ! headers_sent() ) {
     405                        self::$nocache = false;
     406                        nocache_headers();
     407                }
    380408
    381409                set_transient( self::PREFIX . self::$token, $page, self::LIFE );
  • imzura-site-check/tags/1.6.0/includes/class-profiler.php

    r3797325 r3801444  
    2727
    2828        private static $cost = 0;
     29
     30        private static $sig = '';
     31
     32        private static $session = null;
     33
     34        private static $cookies = array();
     35
     36        private static $control = array( '', '' );
     37
     38        private static $sealed = null;
     39
     40        private static $read = array();
    2941
    3042        public static function watch() {
    … …  
    5870                add_action( 'do_meta_boxes', array( __CLASS__, 'boxes' ), PHP_INT_MAX );
    5971
     72                foreach ( array_keys( Options::big() ) as $name ) {
     73                        add_filter( 'option_' . $name, array( __CLASS__, 'read' ), PHP_INT_MAX, 2 );
     74                }
     75
     76                self::notice( '' );
    6077                self::mark();
    6178        }
    … …  
    110127        }
    111128
    112         public static function loaded() {
     129        public static function loaded( $plugin = '' ) {
     130                $began = hrtime( true );
     131
     132                self::notice( is_string( $plugin ) && '' !== $plugin ? Probe::owner_of_path( $plugin ) : '' );
     133
    113134                if ( isset( $GLOBALS['wp_filter']['plugins_loaded'] ) && $GLOBALS['wp_filter']['plugins_loaded'] instanceof \WP_Hook ) {
    114                         $began = hrtime( true );
    115135                        self::mark_hook( $GLOBALS['wp_filter']['plugins_loaded'] );
    116                         self::$cost += hrtime( true ) - $began;
    117                 }
     136                }
     137
     138                self::$cost += hrtime( true ) - $began;
     139        }
     140
     141        public static function seal() {
     142                if ( ! self::$on || null !== self::$sealed ) {
     143                        return;
     144                }
     145
     146                $began = hrtime( true );
     147
     148                self::notice( '' );
     149
     150                $name    = function_exists( 'session_name' ) ? (string) session_name() : '';
     151                $started = self::session() ? ( is_string( self::$session ) ? self::$session : '' ) : null;
     152                $cookies = array();
     153                $control = '';
     154
     155                foreach ( headers_list() as $line ) {
     156                        list( $header, $value ) = self::split( $line );
     157
     158                        if ( 'set-cookie' === $header ) {
     159                                $cookie = self::cookie( $value );
     160
     161                                if ( '' !== $name && $cookie === $name ) {
     162                                        if ( null === $started ) {
     163                                                $started = isset( self::$cookies[ $cookie ] ) ? self::$cookies[ $cookie ] : '';
     164                                        }
     165                                } elseif ( '' !== $cookie && ! isset( $cookies[ $cookie ] ) && count( $cookies ) < 10 ) {
     166                                        $cookies[ $cookie ] = array(
     167                                                'name'  => $cookie,
     168                                                'owner' => isset( self::$cookies[ $cookie ] ) ? self::$cookies[ $cookie ] : '',
     169                                        );
     170                                }
     171                        } elseif ( 'cache-control' === $header ) {
     172                                $control = $value;
     173                        }
     174                }
     175
     176                self::$sealed = array(
     177                        'session' => null !== $started ? array(
     178                                'name'  => '' !== $name ? $name : 'PHPSESSID',
     179                                'owner' => $started,
     180                        ) : null,
     181                        'cookies' => array_values( $cookies ),
     182                        'control' => preg_match( '/\b(no-store|no-cache|private)\b|\bmax-age=0\b/i', $control ) ? array(
     183                                'value' => $control,
     184                                'owner' => $control === self::$control[0] ? self::$control[1] : '',
     185                        ) : null,
     186                );
     187
     188                self::$cost += hrtime( true ) - $began;
     189        }
     190
     191        public static function read( $value, $name = '' ) {
     192                self::$read[ (string) $name ] = true;
     193
     194                return $value;
     195        }
     196
     197        public static function options_read() {
     198                return self::$on ? array_keys( self::$read ) : null;
     199        }
     200
     201        public static function cache() {
     202                self::seal();
     203
     204                return is_array( self::$sealed ) ? self::$sealed : array();
     205        }
     206
     207        private static function notice( $owner ) {
     208                if ( null !== self::$sealed ) {
     209                        return;
     210                }
     211
     212                $session = self::session();
     213                $lines   = headers_list();
     214                $sig     = ( $session ? '1' : '0' ) . implode( "\n", $lines );
     215
     216                if ( $sig === self::$sig ) {
     217                        return;
     218                }
     219
     220                self::$sig = $sig;
     221
     222                if ( self::SELF === $owner ) {
     223                        return;
     224                }
     225
     226                if ( $session && null === self::$session ) {
     227                        self::$session = $owner;
     228                }
     229
     230                foreach ( $lines as $line ) {
     231                        list( $header, $value ) = self::split( $line );
     232
     233                        if ( 'set-cookie' === $header ) {
     234                                $cookie = self::cookie( $value );
     235
     236                                if ( '' !== $cookie && ! isset( self::$cookies[ $cookie ] ) ) {
     237                                        self::$cookies[ $cookie ] = $owner;
     238                                }
     239                        } elseif ( 'cache-control' === $header && $value !== self::$control[0] ) {
     240                                self::$control = array( $value, $owner );
     241                        }
     242                }
     243        }
     244
     245        private static function session() {
     246                return function_exists( 'session_status' ) && PHP_SESSION_ACTIVE === session_status();
     247        }
     248
     249        private static function split( $line ) {
     250                $parts = explode( ':', (string) $line, 2 );
     251
     252                return array( strtolower( trim( $parts[0] ) ), isset( $parts[1] ) ? trim( $parts[1] ) : '' );
     253        }
     254
     255        private static function cookie( $value ) {
     256                return trim( (string) strtok( (string) $value, '=;' ) );
    118257        }
    119258
    … …  
    217356                $top = count( self::$stack ) - 1;
    218357
     358                self::notice( $top >= 0 ? self::$stack[ $top ][0] : '' );
     359
    219360                while ( $top >= 0 && self::$stack[ $top ][1] >= $depth ) {
    220361                        self::close( $now );
  • imzura-site-check/tags/1.6.0/includes/class-rest.php

    r3797325 r3801444  
    4242                                                                                'stranger' => true,
    4343                                                                                'scan'     => true,
     44                                                                                'tap'      => true,
    4445                                                                        )
    4546                                                                ),
    … …  
    114115                register_rest_route(
    115116                        self::SPACE,
     117                        '/tidy/autoload/(?P<step>run|undo)',
     118                        array(
     119                                'methods'             => 'POST',
     120                                'permission_callback' => array( __CLASS__, 'allowed' ),
     121                                'callback'            => array( __CLASS__, 'autoload' ),
     122                        )
     123                );
     124
     125                register_rest_route(
     126                        self::SPACE,
    116127                        '/fixes/(?P<id>[a-z0-9-]+)/(?P<step>trial|prepare|verdict|off)',
    117128                        array(
    … …  
    136147        }
    137148
     149        public static function autoload( \WP_REST_Request $request ) {
     150                $result = 'run' === $request['step'] ? Options::run() : Options::undo();
     151
     152                return is_wp_error( $result ) ? $result : rest_ensure_response( array( 'autoload' => $result ) );
     153        }
     154
    138155        public static function fix( \WP_REST_Request $request ) {
    139156                $fixes = Fixer::all();
  • imzura-site-check/tags/1.6.0/includes/fixes/class-contact-form-7.php

    r3797325 r3801444  
    1111final class Contact_Form_7 extends Fix {
    1212
    13         const SEEN    = 'speed_doctor_form_page';
    14         const TAGS    = array( 'contact-form-7', 'contact-form' );
    15         const STYLES  = array( 'contact-form-7', 'contact-form-7-rtl', 'jquery-ui-smoothness', 'astra-contact-form-7' );
    16         const EARLY   = array( 'cloudflare-turnstile' );
    17         const SCRIPTS = array( 'contact-form-7', 'contact-form-7-html5-fallback', 'wpcf7-recaptcha' );
     13        const SEEN     = 'speed_doctor_form_page';
     14        const TAGS     = array( 'contact-form-7', 'contact-form' );
     15        const STYLES   = array( 'contact-form-7', 'contact-form-7-rtl', 'jquery-ui-smoothness', 'astra-contact-form-7' );
     16        const EARLY    = array( 'cloudflare-turnstile' );
     17        const SCRIPTS  = array( 'contact-form-7', 'contact-form-7-html5-fallback', 'wpcf7-recaptcha' );
     18        const BUILDERS = array( '_elementor_data', '_fl_builder_data', '_bricks_page_content_2', 'ct_builder_shortcodes' );
    1819
    1920        private $built = false;
    … …  
    3738        public function unavailable() {
    3839                return defined( 'WPCF7_VERSION' ) ? '' : __( 'Contact Form 7 is not active on this site.', 'imzura-site-check' );
    39         }
    40 
    41         public function untestable() {
    42                 return $this->targets() ? '' : __( 'No page with a form was found to test on. Open the page that shows your form once, then try again.', 'imzura-site-check' );
    4340        }
    4441
    … …  
    6057                );
    6158                $added   = (int) get_option( self::SEEN, 0 );
     59                $written = $written ? $written : $this->in_builder();
    6260
    6361                if ( $written ) {
    … …  
    196194        }
    197195
     196        private function in_builder() {
     197                $clauses = array( 'relation' => 'OR' );
     198
     199                foreach ( self::BUILDERS as $key ) {
     200                        $clauses[] = array(
     201                                'key'     => $key,
     202                                'value'   => 'contact-form',
     203                                'compare' => 'LIKE',
     204                        );
     205                }
     206
     207                return get_posts(
     208                        array(
     209                                'post_type'   => 'any',
     210                                'post_status' => 'publish',
     211                                'numberposts' => 1,
     212                                'fields'      => 'ids',
     213                                // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- once, when the fix is tried from the admin screen.
     214                                'meta_query'  => $clauses,
     215                        )
     216                );
     217        }
     218
    198219        private function expected() {
    199220                $post = is_singular() ? get_queried_object() : null;
  • imzura-site-check/tags/1.6.0/readme.txt

    r3797865 r3801444  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.5.0
     7Stable tag: 1.6.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    3939* Speed settings of well-known plugins that are off: Elementor (Inline Font Icons, CSS Print Method, optimized image loading, lazy background images, local Google Fonts and their font-display), Formidable Forms styles on every page, Wordfence logging every visit, and the local Google Fonts setting of Astra, Kadence, OceanWP and Spectra (or GeneratePress font-display) when their fonts come from Google. This plugin only reads these settings and names them as each plugin's screen does
    4040* Housekeeping: the PHP error log (whether strangers can download it, its size, the plugins that fill it), backup and archive files left in wp-content, the largest database tables, plugins that are installed but switched off, and two SEO plugins active at once
    41 * Settings WordPress loads on every request (autoloaded options) and the largest of them
     41* Slow taps (Interaction to Next Paint): after the page has loaded, the check taps menus, buttons and tabs (never a link or a form, and with the network held back) and names the plugin or theme whose code made the visitor wait, and scripts that keep the browser busy after the page has loaded
     42* Pages built from too many elements (more than 1,400), how many of them are hidden at phone width, and the largest parts of each page
     43* Pages that no server or CDN cache can keep: the plugin or theme that gives every first-time visitor a cookie or a PHP session, or sends a no-store, no-cache or private header (the cart and the checkout are left out)
     44* Settings WordPress loads on every request (autoloaded options): the largest of them with the plugin or theme each belongs to, active, switched off or removed, and a button that stops loading the ones left behind by plugins and themes that are not active (they stay in the database, and it can be undone)
    4245* Scheduled jobs that have fallen behind, including the Action Scheduler queue
    4346* WooCommerce: order storage, sessions that pile up, the cart script running outside the shop
    … …  
    5861* **Minify stylesheets (CSS)** and **Minify scripts (JavaScript)**, two separate fixes. The spaces, line breaks and comments come out of your theme's and plugins' own files, and a smaller copy is sent instead, under the same handle. Files that are minified already, files from other sites and code written into the page are left alone, and so is a file that would not get at least 5% smaller. Addresses inside stylesheets are rewritten, so fonts and pictures still load. If a script stops working once minified, the trial sees the error in that file, sends it as it is from then on and tests again; the fix is kept only if the pages then work, and the screen shows how many files are sent as they are.
    5962* **Leave out the emoji script.** WordPress adds a script and styles to every page so that very old browsers can show emoji as pictures. Browsers in use today show emoji themselves.
     63* **Stop Heartbeat calls from visitors.** When a plugin loads WordPress Heartbeat on public pages, every open tab calls admin-ajax.php again and again, past any page cache. Before the trial this plugin calls admin-ajax.php itself as a visitor and looks at what answers Heartbeat there; only when nothing does is the Heartbeat file left out, with a stand-in that keeps the scripts that asked for it working. Logged-in users keep Heartbeat.
    6064* **Load jQuery without jQuery Migrate.** Migrate only helps code written for old versions of jQuery. If a script on your site still needs it, the test sees it fail and the fix is not kept.
    6165* **Load scripts in the head with defer.** Scripts in the head of the page make the browser wait before it shows anything. With the fix they download alongside the page and run once it is read, in the same order as before. jQuery is left as it is, because code written into pages often needs it right away. Needs WordPress 6.3 or newer.
    6266* **Show YouTube videos as a picture until play is pressed.** An embedded YouTube video loads the whole player as soon as the page opens, even for visitors who never watch it. With the fix the video shows its picture, from YouTube, and a play button in the same place and size, and the player loads when the button is pressed. Needs WordPress 6.9 or newer.
     67* **Show Google Maps as a button until the visitor asks for the map.** An embedded Google Map loads its whole map viewer as soon as the page opens, even for visitors who never look at it. With the fix the map keeps its place and size and shows a button; the map loads when the button is pressed. Needs WordPress 6.9 or newer.
    6368
    6469The screen has a tab for each kind of fix (CSS & JS, Images, Plugins), one for the check, and one for your page cache: which one is active, a test that opens the home page as a new visitor, and a button that clears it.
    … …  
    115120Yes. The people behind this plugin fix slow WordPress and WooCommerce sites for a fixed price, on a copy of the site first, with a before-and-after measurement: [imzura.com](https://imzura.com/services/wordpress-speed-optimization?utm_source=imzura-site-check&utm_medium=readme). The plugin works the same whether you ask or not.
    116121
     122= Site Health says "Autoloaded options could affect performance". Can this plugin help? =
     123
     124Yes. The check lists the largest settings WordPress loads on every request and the plugin or theme each one belongs to. Settings left behind by plugins and themes that are switched off or removed, and not read on any page the check opened, can be taken off the every-request list with one button. Nothing is deleted, a plugin that comes back still finds its settings, and the button next to it puts everything back.
     125
     126= My host or Cloudflare should cache my pages, but every visit is a miss. Why? =
     127
     128Run the check: it names the plugin or theme that gives every first-time visitor a cookie or a PHP session, or sends a header that tells caches not to keep the page. Server and CDN caches do not keep such pages by default. Look in that plugin's settings for a way to set the cookie only when it is needed, or ask its author.
     129
    117130= Does it replace my cache plugin? =
    118131
    … …  
    178191
    179192== Changelog ==
     193
     194= 1.6.0 =
     195* New check: slow taps (Interaction to Next Paint). After the page has loaded, the check taps up to five menus, buttons or tabs and names the plugin or theme whose click code made the visitor wait, and scripts that keep the browser busy after load.
     196* New check: pages built from more than 1,400 elements, with how many are hidden at phone width and the largest parts.
     197* New check: pages that no server or CDN cache can keep, with the plugin or theme that gives every first-time visitor a cookie or a PHP session, or marks the page no-store, no-cache or private.
     198* The autoloaded settings finding names the plugin or theme behind each large entry, and a button stops loading the entries of plugins and themes that are not active or were removed (undo puts them back). Needs WordPress 6.4 or newer.
     199* New fix: Google Maps embeds show a button in the same place and size, and the map loads when the visitor asks for it.
     200* A layout shift now names what was added while the page loaded and pushed the content down, not only what moved.
     201* The Contact Form 7 fix can be tried on a site where no page shows a form, and it finds forms kept in page-builder data (Elementor, Beaver Builder, Bricks, Oxygen).
    180202
    181203= 1.5.0 =
  • imzura-site-check/tags/1.6.0/uninstall.php

    r3797325 r3801444  
    1515delete_option( 'speed_doctor_fonts' );
    1616delete_option( 'speed_doctor_tidy' );
     17delete_option( 'speed_doctor_autoload_spare' );
     18delete_option( 'speed_doctor_autoload_off' );
    1719delete_metadata( 'user', 0, 'speed_doctor_review', '', true );
    1820
  • imzura-site-check/trunk/assets/admin.js

    r3797865 r3801444  
    2121        let tidy = data.tidy || null;
    2222        let tidyNote = '';
     23        let spare = data.spare || null;
     24        let spareNote = '';
    2325        let lastReport = data.report;
    2426        let busy = false;
    … …  
    153155                                const fix = finding.fix && fixes.find( ( item ) => item.id === finding.fix );
    154156
    155                                 if ( finding.fix === 'tidy:revisions' && tidy ) {
     157                                if ( finding.id === 'autoload' && ( spare || spareNote || finding.fix === 'tidy:autoload' ) ) {
     158                                        card.append( spareBlock( finding.fix === 'tidy:autoload' ) );
     159                                } else if ( finding.fix === 'tidy:revisions' && tidy ) {
    156160                                        card.append( el( 'p', '', text.tidy_card ) );
    157161                                } else if ( finding.fix === 'tidy:revisions' ) {
    … …  
    250254                        const targets = started.targets;
    251255                        const pages = {};
    252                         const busy = {};
     256                        const frames = {};
    253257                        let reading = '';
    254258                        let watcher = null;
    255259
     260                        function take( entries ) {
     261                                entries.forEach( ( entry ) => {
     262                                        if ( reading ) {
     263                                                frames[ reading ].push( {
     264                                                        at: performance.timeOrigin + entry.startTime,
     265                                                        scripts: ( entry.scripts || [] ).filter( ( script ) => script.windowAttribution === 'descendant' ).map( ( script ) => ( { url: String( script.sourceURL || '' ).split( /[?#]/ )[ 0 ], ms: script.duration } ) ),
     266                                                } );
     267                                        }
     268                                } );
     269                        }
     270
     271                        function costs( list, keep, limit ) {
     272                                const found = {};
     273
     274                                list.forEach( ( item ) => {
     275                                        if ( keep( item ) ) {
     276                                                item.scripts.forEach( ( script ) => {
     277                                                        if ( script.url ) {
     278                                                                found[ script.url ] = ( found[ script.url ] || 0 ) + script.ms;
     279                                                        }
     280                                                } );
     281                                        }
     282                                } );
     283
     284                                return Object.keys( found ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( found[ url ] ) } ) ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, limit );
     285                        }
     286
     287                        function measured( list, poke ) {
     288                                const cut = poke && poke.from ? poke.from : Infinity;
     289                                const quiet = poke && poke.idle ? poke.idle : null;
     290                                const taps = poke && Array.isArray( poke.taps ) ? poke.taps : [];
     291
     292                                return {
     293                                        busy: costs( list, ( item ) => item.at < cut, 20 ),
     294                                        idle: quiet ? costs( list, ( item ) => item.at >= quiet.from && item.at < quiet.to, 10 ) : [],
     295                                        taps: taps.slice( 0, 8 ).map( ( tap ) => ( {
     296                                                what: String( tap.what || '' ).slice( 0, 80 ),
     297                                                ms: Math.round( tap.ms ) || 0,
     298                                                handled: Math.round( tap.handled ) || 0,
     299                                                scripts: ( Array.isArray( tap.scripts ) ? tap.scripts : [] ).slice( 0, 5 ),
     300                                        } ) ),
     301                                        nodes: poke && poke.nodes ? poke.nodes : 0,
     302                                };
     303                        }
     304
    256305                        try {
    257                                 watcher = new PerformanceObserver( ( list ) => list.getEntries().forEach( ( entry ) => ( entry.scripts || [] ).forEach( ( script ) => {
    258                                         const url = String( script.sourceURL || '' ).split( /[?#]/ )[ 0 ];
    259 
    260                                         if ( reading && url && script.windowAttribution === 'descendant' ) {
    261                                                 busy[ reading ][ url ] = ( busy[ reading ][ url ] || 0 ) + script.duration;
    262                                         }
    263                                 } ) ) );
     306                                watcher = new PerformanceObserver( ( list ) => take( list.getEntries() ) );
    264307                                watcher.observe( { type: 'long-animation-frame' } );
    265308                        } catch ( error ) {
    … …  
    272315                                meter.value = i;
    273316                                reading = targets[ i ].kind;
    274                                 busy[ reading ] = {};
     317                                frames[ reading ] = [];
    275318
    276319                                const seen = await open( Object.assign( { screen: 'phone', scan: true }, targets[ i ] ) );
    277320
     321                                if ( watcher ) {
     322                                        take( watcher.takeRecords() );
     323                                }
     324
    278325                                if ( seen ) {
    279                                         pages[ reading ] = { errors: seen.errors, sources: seen.sources, look: Object.assign( {}, seen.look, { busy: Object.keys( busy[ reading ] ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( busy[ reading ][ url ] ) } ) ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, 20 ) } ) };
     326                                        pages[ reading ] = { errors: seen.errors, sources: seen.sources, look: Object.assign( {}, seen.look, measured( frames[ reading ], seen.taps ) ) };
    280327                                }
    281328                        }
    … …  
    608655        }
    609656
     657        function spareBlock( offer ) {
     658                const box = el( 'div', 'speed-doctor-spare' );
     659                const actions = el( 'div', 'speed-doctor-actions imz-actions' );
     660
     661                if ( spareNote ) {
     662                        box.append( el( 'p', '', spareNote ) );
     663                }
     664
     665                if ( offer ) {
     666                        actions.append( spareButton( text.spare_go, 'run', true ) );
     667                }
     668
     669                if ( spare ) {
     670                        box.append( el( 'p', '', fill( text.spare_done, [ spare.count.toLocaleString(), size( spare.bytes ), new Date( spare.time * 1000 ).toLocaleString() ] ) ) );
     671                        actions.append( spareButton( text.spare_undo, 'undo', false ) );
     672                }
     673
     674                if ( actions.childNodes.length ) {
     675                        box.append( actions );
     676                }
     677
     678                return box;
     679        }
     680
     681        function spareButton( label, step, primary ) {
     682                const go = el( 'button', primary ? 'button button-primary imz-btn imz-btn--primary' : 'button imz-btn', label );
     683                go.type = 'button';
     684                go.disabled = busy;
     685                go.addEventListener( 'click', () => spareStep( step ) );
     686                return go;
     687        }
     688
     689        async function spareStep( step ) {
     690                if ( busy ) {
     691                        return;
     692                }
     693
     694                busy = true;
     695                spareNote = '';
     696
     697                try {
     698                        const answer = ( await call( '/tidy/autoload/' + step, 'POST' ) ).autoload;
     699
     700                        if ( step === 'run' ) {
     701                                spare = answer;
     702                                ( lastReport ? lastReport.findings : [] ).forEach( ( finding ) => {
     703                                        if ( finding.id === 'autoload' ) {
     704                                                finding.fix = '';
     705                                        }
     706                                } );
     707                        } else {
     708                                spare = null;
     709                                spareNote = fill( text.spare_back, [ answer.restored.toLocaleString() ] );
     710                        }
     711                } catch ( error ) {
     712                        spareNote = error.reason || text.spare_failed;
     713                }
     714
     715                busy = false;
     716                refresh();
     717        }
     718
    610719        function tidyButton( label, step, primary ) {
    611720                const go = el( 'button', primary ? 'button button-primary imz-btn imz-btn--primary' : 'button imz-btn', label );
    … …  
    703812                        const frame = el( 'iframe', 'speed-doctor-frame' + ( load.screen === 'phone' ? ' is-phone' : '' ) + ( load.scan ? ' is-scan' : '' ) );
    704813                        let timer = 0;
     814                        let got = null;
    705815
    706816                        function finish( report ) {
    … …  
    712822
    713823                        function hear( event ) {
    714                                 if ( event.source === frame.contentWindow && event.data && event.data.speedDoctor === load.token ) {
     824                                if ( event.source !== frame.contentWindow || ! event.data || event.data.speedDoctor !== load.token ) {
     825                                        return;
     826                                }
     827
     828                                if ( got ) {
     829                                        if ( event.data.taps ) {
     830                                                got.taps = event.data.taps;
     831                                                finish( got );
     832                                        }
     833                                } else if ( event.data.report && load.scan && ! load.admin ) {
     834                                        got = event.data.report;
     835                                        clearTimeout( timer );
     836                                        timer = setTimeout( () => finish( got ), 15000 );
     837                                } else if ( event.data.report ) {
    715838                                        finish( event.data.report );
    716839                                }
    … …  
    724847
    725848                        frame.addEventListener( 'load', () => {
     849                                if ( got ) {
     850                                        return;
     851                                }
     852
    726853                                clearTimeout( timer );
    727854                                timer = setTimeout( () => finish( null ), load.admin ? 300 : 20000 );
    … …  
    10071134                        refresh();
    10081135                        say( fix, error.reason || text.trial_failed );
    1009                 }
     1136
     1137                        return error.reason || '';
     1138                }
     1139
     1140                return '';
    10101141        }
    10111142
    … …  
    10461177                trial: async ( id ) => {
    10471178                        const fix = fixes.find( ( item ) => item.id === id );
     1179                        let refused = '';
    10481180
    10491181                        if ( fix && ! busy ) {
    1050                                 await trial( fix );
    1051                         }
    1052 
    1053                         return fixes.find( ( item ) => item.id === id ) || null;
     1182                                refused = await trial( fix );
     1183                        }
     1184
     1185                        const found = fixes.find( ( item ) => item.id === id );
     1186
     1187                        return found && refused ? Object.assign( {}, found, { refused: refused } ) : found || null;
    10541188                },
    10551189                tidy: async ( step ) => {
  • imzura-site-check/trunk/assets/probe.js

    r3797416 r3801444  
    1212        let pending = 0;
    1313        let fresh = true;
     14        let poking = false;
    1415
    1516        const listen = EventTarget.prototype.addEventListener;
     17        const unlisten = EventTarget.prototype.removeEventListener;
    1618        const told = new WeakMap();
    17 
    18         EventTarget.prototype.addEventListener = function ( type ) {
     19        const KINDS = /^(click|pointerdown|pointerup|mousedown|mouseup|touchstart|touchend)$/;
     20        const timed = new WeakMap();
     21        const nest = [];
     22        let ledger = null;
     23
     24        function origin( stack ) {
     25                const lines = String( stack || '' ).match( /https?:\/\/[^\s()'"@]+?:\d+:\d+/g ) || [];
     26
     27                for ( let i = 1; i < lines.length; i++ ) {
     28                        const url = lines[ i ].replace( /:\d+:\d+$/, '' ).split( /[?#]/ )[ 0 ];
     29
     30                        if ( ! /\/jquery(-migrate)?(-\d[\w.]*)?(\.min)?\.js$/.test( url ) ) {
     31                                return url;
     32                        }
     33                }
     34
     35                return '';
     36        }
     37
     38        function stopwatch( listener, from ) {
     39                const run = function () {
     40                        const began = performance.now();
     41
     42                        nest.push( 0 );
     43
     44                        try {
     45                                return typeof listener === 'function' ? listener.apply( this, arguments ) : listener.handleEvent.apply( listener, arguments );
     46                        } finally {
     47                                const total = performance.now() - began;
     48                                const inner = nest.pop();
     49
     50                                if ( nest.length ) {
     51                                        nest[ nest.length - 1 ] += total;
     52                                }
     53
     54                                if ( ledger ) {
     55                                        ledger[ from ] = ( ledger[ from ] || 0 ) + total - inner;
     56                                }
     57                        }
     58                };
     59
     60                run.speedDoctor = true;
     61
     62                return run;
     63        }
     64
     65        function watched( type, listener ) {
     66                return probe.tap && listener && ! listener.speedDoctor && KINDS.test( String( type ) ) && ( typeof listener === 'function' || typeof listener.handleEvent === 'function' );
     67        }
     68
     69        EventTarget.prototype.addEventListener = function ( type, listener ) {
    1970                if ( this instanceof Element && heard.length < 5000 ) {
    2071                        const kinds = told.get( this ) || new Set();
    … …  
    2677                }
    2778
     79                if ( watched( type, listener ) ) {
     80                        try {
     81                                if ( ! timed.has( listener ) ) {
     82                                        timed.set( listener, stopwatch( listener, origin( new Error().stack ) ) );
     83                                }
     84
     85                                const args = Array.prototype.slice.call( arguments );
     86                                args[ 1 ] = timed.get( listener );
     87
     88                                return listen.apply( this, args );
     89                        } catch ( error ) {
     90                        }
     91                }
     92
    2893                return listen.apply( this, arguments );
    2994        };
     95
     96        if ( probe.tap ) {
     97                EventTarget.prototype.removeEventListener = function ( type, listener ) {
     98                        if ( listener && KINDS.test( String( type ) ) && timed.has( listener ) ) {
     99                                const args = Array.prototype.slice.call( arguments );
     100                                args[ 1 ] = timed.get( listener );
     101
     102                                return unlisten.apply( this, args );
     103                        }
     104
     105                        return unlisten.apply( this, arguments );
     106                };
     107
     108                const hook = ( jq ) => {
     109                        try {
     110                                if ( ! jq || ! jq.event || typeof jq.event.add !== 'function' || jq.event.add.speedDoctor ) {
     111                                        return;
     112                                }
     113
     114                                const add = jq.event.add;
     115
     116                                jq.event.add = function ( elem, types, handler ) {
     117                                        try {
     118                                                const fn = handler && handler.handler ? handler.handler : handler;
     119
     120                                                if ( typeof types === 'string' && typeof fn === 'function' && ! fn.speedDoctor && /(^|\s)(click|pointerdown|pointerup|mousedown|mouseup|touchstart|touchend)(\.|\s|$)/.test( types ) ) {
     121                                                        if ( ! fn.guid ) {
     122                                                                fn.guid = jq.guid++;
     123                                                        }
     124
     125                                                        const run = stopwatch( fn, origin( new Error().stack ) );
     126                                                        const args = Array.prototype.slice.call( arguments );
     127
     128                                                        run.guid = fn.guid;
     129                                                        args[ 2 ] = handler && handler.handler ? Object.assign( {}, handler, { handler: run } ) : run;
     130
     131                                                        return add.apply( this, args );
     132                                                }
     133                                        } catch ( error ) {
     134                                        }
     135
     136                                        return add.apply( this, arguments );
     137                                };
     138
     139                                jq.event.add.speedDoctor = true;
     140                        } catch ( error ) {
     141                        }
     142                };
     143
     144                let held = window.jQuery;
     145
     146                hook( held );
     147
     148                try {
     149                        Object.defineProperty( window, 'jQuery', {
     150                                configurable: true,
     151                                enumerable: true,
     152                                get: () => held,
     153                                set: ( value ) => {
     154                                        held = value;
     155                                        hook( value );
     156                                },
     157                        } );
     158                } catch ( error ) {
     159                }
     160        }
    30161
    31162        function memory() {
    … …  
    67198        };
    68199
    69         const painted = { lcp: null, shift: 0, shifters: [] };
     200        const painted = { lcp: null, shift: 0, shifters: [], pushers: [] };
     201        const added = [];
    70202
    71203        function observe( type, take ) {
    … …  
    84216        }
    85217
     218        if ( probe.scan && window.MutationObserver ) {
     219                new MutationObserver( ( list ) => {
     220                        const at = performance.now();
     221
     222                        while ( added.length && added[ 0 ][ 0 ] < at - 3000 ) {
     223                                added.shift();
     224                        }
     225
     226                        list.forEach( ( change ) => change.addedNodes.forEach( ( node ) => {
     227                                if ( 1 === node.nodeType && added.length < 400 && ! /^(SCRIPT|STYLE|LINK|META|NOSCRIPT|TEMPLATE|BR)$/.test( node.nodeName ) ) {
     228                                        added.push( [ at, node ] );
     229                                }
     230                        } ) );
     231                } ).observe( document.documentElement, { childList: true, subtree: true } );
     232        }
     233
     234        function pusher( entry ) {
     235                let top = Infinity;
     236                let best = null;
     237                let tallest = 0;
     238
     239                ( entry.sources || [] ).forEach( ( source ) => {
     240                        top = Math.min( top, source.previousRect ? source.previousRect.top : Infinity );
     241                } );
     242
     243                added.forEach( ( item ) => {
     244                        const node = item[ 1 ];
     245
     246                        if ( item[ 0 ] > entry.startTime || item[ 0 ] < entry.startTime - 1000 || ! node.isConnected ) {
     247                                return;
     248                        }
     249
     250                        if ( ( entry.sources || [] ).some( ( source ) => source.node && ( node === source.node || node.contains( source.node ) ) ) ) {
     251                                return;
     252                        }
     253
     254                        const box = node.getBoundingClientRect();
     255
     256                        if ( box.height > tallest && box.width > 0 && box.top <= top + 1 ) {
     257                                tallest = box.height;
     258                                best = node;
     259                        }
     260                } );
     261
     262                return best;
     263        }
     264
    86265        if ( probe.scan && window.PerformanceObserver ) {
    87266                observe( 'layout-shift', ( entry ) => {
    88267                        if ( ! entry.hadRecentInput ) {
     268                                const cause = pusher( entry );
     269
    89270                                painted.shift += entry.value;
    90271                                ( entry.sources || [] ).forEach( ( source ) => source.node && painted.shifters.push( [ entry.value, source.node ] ) );
     272
     273                                if ( cause ) {
     274                                        painted.pushers.push( [ entry.value, cause ] );
     275                                }
    91276                        }
    92277                } );
    … …  
    94279
    95280        function note( kind, detail, file ) {
     281                if ( poking ) {
     282                        return;
     283                }
     284
    96285                const said = String( detail ).replace( /^Uncaught\s+/, '' ).replace( /^\(in promise\)\s+/, '' ).replace( /^[A-Za-z]*Error:\s+/, '' );
    97286                const key = kind + ': ' + said.slice( 0, 160 );
    … …  
    147336                const started = performance.now();
    148337
     338                if ( poking ) {
     339                        return;
     340                }
     341
    149342                if ( own( request.speedDoctorUrl ) ) {
    150343                        try {
    … …  
    166359                        const url = typeof input === 'string' ? input : ( input && input.url ) || String( input );
    167360                        const started = performance.now();
     361
     362                        if ( poking ) {
     363                                return new Promise( () => {} );
     364                        }
    168365
    169366                        if ( own( url ) ) {
    … …  
    186383                        );
    187384                };
     385        }
     386
     387        if ( probe.tap ) {
     388                try {
     389                        const beacon = navigator.sendBeacon;
     390                        const popup = window.open;
     391
     392                        if ( beacon ) {
     393                                navigator.sendBeacon = function () {
     394                                        return poking ? true : beacon.apply( navigator, arguments );
     395                                };
     396                        }
     397
     398                        window.open = function () {
     399                                return poking ? null : popup.apply( window, arguments );
     400                        };
     401                } catch ( error ) {
     402                }
     403
     404                [ 'click', 'submit', 'auxclick' ].forEach( ( type ) => listen.call( window, type, ( event ) => poking && event.preventDefault(), true ) );
    188405        }
    189406
    … …  
    554771
    555772                return found;
     773        }
     774
     775        function dom() {
     776                const all = document.body ? document.body.getElementsByTagName( '*' ) : [];
     777                const total = all.length;
     778                const size = new Map();
     779
     780                if ( ! total || total > 60000 ) {
     781                        return { total: total, hidden: 0, parts: [] };
     782                }
     783
     784                for ( let i = total - 1; i >= 0; i-- ) {
     785                        const own = ( size.get( all[ i ] ) || 0 ) + 1;
     786                        const up = all[ i ].parentElement;
     787
     788                        size.set( all[ i ], own );
     789
     790                        if ( up && up !== document.body ) {
     791                                size.set( up, ( size.get( up ) || 0 ) + own );
     792                        }
     793                }
     794
     795                const parts = [];
     796                const big = Array.from( size.keys() ).filter( ( node ) => size.get( node ) >= total * 0.15 ).sort( ( a, b ) => size.get( b ) - size.get( a ) );
     797
     798                for ( let i = 0; i < big.length && parts.length < 3; i++ ) {
     799                        const node = big[ i ];
     800                        const most = Array.prototype.reduce.call( node.children, ( top, child ) => Math.max( top, size.get( child ) || 0 ), 0 );
     801
     802                        if ( most <= size.get( node ) * 0.6 && ! parts.some( ( part ) => part.node.contains( node ) || node.contains( part.node ) ) ) {
     803                                parts.push( { node: node, count: size.get( node ) } );
     804                        }
     805                }
     806
     807                let hidden = 0;
     808                let skip = null;
     809
     810                for ( let i = 0; i < total && i < 20000; i++ ) {
     811                        if ( skip && skip.contains( all[ i ] ) ) {
     812                                continue;
     813                        }
     814
     815                        if ( getComputedStyle( all[ i ] ).display === 'none' ) {
     816                                hidden += size.get( all[ i ] ) || 1;
     817                                skip = all[ i ];
     818                        }
     819                }
     820
     821                return { total: total, hidden: hidden, parts: parts.map( ( part ) => ( { what: describe( part.node ), count: part.count } ) ) };
    556822        }
    557823
    … …  
    611877                        shift: Math.round( painted.shift * 1000 ) / 1000,
    612878                        shifters: painted.shifters.sort( ( a, b ) => b[ 0 ] - a[ 0 ] ).map( ( item ) => describe( item[ 1 ] ) ).filter( ( what, i, all ) => what && all.indexOf( what ) === i ).slice( 0, 3 ),
     879                        pushers: painted.pushers.sort( ( a, b ) => b[ 0 ] - a[ 0 ] ).map( ( item ) => describe( item[ 1 ] ) ).filter( ( what, i, all ) => what && all.indexOf( what ) === i ).slice( 0, 2 ),
    613880                        lazyTop: lazyTop,
    614881                        sizeless: sizeless,
    … …  
    618885                        styles: usage(),
    619886                        links: links(),
     887                        dom: dom(),
    620888                };
     889        }
     890
     891        const RISKY = /(^|[^a-z])(cart|checkout|basket|buy|order|pay|purchase|log-?in|log-?out|sign-?in|sign-?up|register|account|delete|remove|subscribe|submit|wishlist|compare|book|reserv|download|print|share|call|phone|mailto)/i;
     892
     893        function wait( ms ) {
     894                return new Promise( ( resolve ) => setTimeout( resolve, ms ) );
     895        }
     896
     897        function stamp() {
     898                return Math.round( performance.timeOrigin + performance.now() );
     899        }
     900
     901        function tappable( node ) {
     902                if ( node.closest( 'form, [contenteditable="true"], [contenteditable=""]' ) || node.closest( 'a[href]:not([href^="#"])' ) ) {
     903                        return false;
     904                }
     905
     906                if ( node.matches( '[disabled], [aria-disabled="true"], [type="submit"], [type="reset"], [onclick*="location"]' ) ) {
     907                        return false;
     908                }
     909
     910                const words = [ node.id, typeof node.className === 'string' ? node.className : '', node.getAttribute( 'name' ), node.getAttribute( 'href' ), node.getAttribute( 'aria-label' ), ( node.textContent || '' ).slice( 0, 80 ) ].join( ' ' );
     911
     912                if ( RISKY.test( words ) ) {
     913                        return false;
     914                }
     915
     916                const box = node.getBoundingClientRect();
     917
     918                if ( box.width < 8 || box.height < 8 || box.bottom < 0 || box.top > window.innerHeight * 2 ) {
     919                        return false;
     920                }
     921
     922                const style = getComputedStyle( node );
     923
     924                return style.visibility !== 'hidden' && style.pointerEvents !== 'none';
     925        }
     926
     927        function candidates() {
     928                const found = [];
     929                const named = new Set();
     930                const list = document.querySelectorAll( '[aria-expanded], [aria-controls], [aria-haspopup], summary, [role="tab"], button, [role="button"], a[href^="#"]' );
     931
     932                for ( let i = 0; i < list.length && found.length < 5; i++ ) {
     933                        const name = describe( list[ i ] );
     934
     935                        if ( ! named.has( name ) && tappable( list[ i ] ) ) {
     936                                named.add( name );
     937                                found.push( list[ i ] );
     938                        }
     939                }
     940
     941                const middle = document.elementFromPoint( window.innerWidth / 2, Math.min( window.innerHeight / 2, 300 ) );
     942
     943                if ( middle && middle !== document.documentElement && ! middle.closest( 'a, button, input, select, textarea, label, summary, [role="button"], [onclick], form' ) ) {
     944                        found.push( middle );
     945                }
     946
     947                return found;
     948        }
     949
     950        function tap( node ) {
     951                const box = node.getBoundingClientRect();
     952                const at = { bubbles: true, cancelable: true, composed: true, view: window, clientX: box.left + box.width / 2, clientY: box.top + box.height / 2, button: 0 };
     953                const pointer = Object.assign( { pointerId: 1, pointerType: 'touch', isPrimary: true }, at );
     954                const what = describe( node );
     955                const from = stamp();
     956                const started = performance.now();
     957
     958                ledger = {};
     959
     960                [ 'pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click' ].forEach( ( type ) => {
     961                        const touch = type.indexOf( 'pointer' ) === 0 && window.PointerEvent;
     962
     963                        try {
     964                                node.dispatchEvent( touch ? new PointerEvent( type, pointer ) : new MouseEvent( type, at ) );
     965                        } catch ( error ) {
     966                        }
     967                } );
     968
     969                const handled = Math.round( performance.now() - started );
     970                const spent = ledger;
     971
     972                ledger = null;
     973
     974                const scripts = Object.keys( spent ).map( ( url ) => ( { url: url.slice( 0, 300 ), ms: Math.round( spent[ url ] ) } ) ).filter( ( item ) => item.ms > 0 ).sort( ( a, b ) => b.ms - a.ms ).slice( 0, 5 );
     975
     976                return new Promise( ( resolve ) => {
     977                        let done = false;
     978
     979                        function finish() {
     980                                if ( ! done ) {
     981                                        done = true;
     982                                        resolve( { what: what, at: from, handled: handled, ms: Math.round( performance.now() - started ), scripts: scripts } );
     983                                }
     984                        }
     985
     986                        requestAnimationFrame( () => setTimeout( finish, 0 ) );
     987                        setTimeout( finish, 1500 );
     988                } );
     989        }
     990
     991        async function poke() {
     992                poking = true;
     993
     994                const result = { from: stamp(), idle: null, taps: [], nodes: document.getElementsByTagName( '*' ).length };
     995
     996                try {
     997                        const quiet = stamp();
     998
     999                        await wait( 1500 );
     1000                        result.idle = { from: quiet, to: stamp() };
     1001
     1002                        const list = candidates();
     1003
     1004                        for ( let i = 0; i < list.length; i++ ) {
     1005                                if ( list[ i ].isConnected ) {
     1006                                        result.taps.push( await tap( list[ i ] ) );
     1007                                        await wait( 200 );
     1008                                }
     1009                        }
     1010                } catch ( error ) {
     1011                }
     1012
     1013                result.to = stamp();
     1014
     1015                return result;
    6211016        }
    6221017
    … …  
    6591054                                clearInterval( timer );
    6601055                                report();
     1056
     1057                                if ( probe.tap ) {
     1058                                        poke().then( ( taps ) => window.parent.postMessage( { speedDoctor: probe.token, taps: taps }, probe.origin ) );
     1059                                }
    6611060                        }
    6621061                }, 250 );
  • imzura-site-check/trunk/imzura-site-check.php

    r3797865 r3801444  
    22/**
    33 * Plugin Name:       imzura Site Check – Speed & Site Optimization
    4  * Plugin URI:        https://imzura.com/products/speed-doctor
     4 * Plugin URI:        https://imzura.com/products/site-check
    55 * Description:       Finds what slows your site down, on the front end, in the admin and in WooCommerce, and proves every fix with a measurement.
    6  * Version:           1.5.0
     6 * Version:           1.6.0
    77 * Requires at least: 6.2
    88 * Requires PHP:      7.4
    … …  
    1818defined( 'ABSPATH' ) || exit;
    1919
    20 define( 'SPEED_DOCTOR_VERSION', '1.5.0' );
     20define( 'SPEED_DOCTOR_VERSION', '1.6.0' );
    2121define( 'SPEED_DOCTOR_FILE', __FILE__ );
    2222define( 'SPEED_DOCTOR_DIR', plugin_dir_path( __FILE__ ) );
  • imzura-site-check/trunk/includes/checks/class-autoload.php

    r3797325 r3801444  
    55
    66use SpeedDoctor\Check;
     7use SpeedDoctor\Options;
    78
    89defined( 'ABSPATH' ) || exit;
    … …  
    1213        const WARN_KB = 400;
    1314        const HIGH_KB = 800;
     15        const TOP     = 6;
     16
     17        private $admin = array();
     18
     19        public function admin( array $pages ) {
     20                $this->admin = $pages;
     21        }
    1422
    1523        public function run( array $pages ) {
    … …  
    1927                $total = (int) $wpdb->get_var( "SELECT SUM( LENGTH( option_value ) ) FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' )" );
    2028                $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' )" );
    21                 $top   = $wpdb->get_results( "SELECT option_name, LENGTH( option_value ) AS size FROM {$wpdb->options} WHERE autoload IN ( 'yes', 'on', 'auto', 'auto-on' ) ORDER BY size DESC LIMIT 5" );
    2229                // phpcs:enable
    2330
    24                 $kb = (int) round( $total / 1024 );
     31                $kb    = (int) round( $total / 1024 );
     32                $read  = $this->read( array_merge( $pages, $this->admin ) );
     33                $spare = null === $read || $kb < self::WARN_KB ? array() : Options::spare( $read );
     34
     35                Options::remember( Options::available() ? $spare : array() );
    2536
    2637                if ( $kb < self::WARN_KB ) {
    … …  
    3950                $facts = array();
    4051
    41                 foreach ( (array) $top as $row ) {
    42                         $facts[] = sprintf( '%s — %s', $row->option_name, $this->kb( (int) round( $row->size / 1024 ) ) );
     52                foreach ( array_slice( Options::big(), 0, self::TOP, true ) as $name => $size ) {
     53                        $facts[] = sprintf( '%1$s — %2$s · %3$s', $name, $this->kb( max( 1, (int) round( $size / 1024 ) ) ), $this->owner( Options::owner( $name ) ) );
     54                }
     55
     56                $detail = __( 'This is read from the database before every page and every admin screen, and no page cache can skip it. WordPress\'s Site Health marks more than 800 KB as a problem. The largest entries are listed below with the plugin or theme they belong to.', 'imzura-site-check' );
     57                $fix    = '';
     58
     59                if ( $spare && Options::available() ) {
     60                        $detail .= ' ' . sprintf(
     61                                /* translators: 1: size, 2: number of settings */
     62                                __( '%1$s of it (%2$s entries) belongs to plugins and themes that are not active or were removed, and none of the pages checked read it. The button below stops loading those entries on every request. They stay in the database, so a plugin that comes back still finds its settings, and it can be undone.', 'imzura-site-check' ),
     63                                $this->kb( max( 1, (int) round( array_sum( $spare ) / 1024 ) ) ),
     64                                number_format_i18n( count( $spare ) )
     65                        );
     66                        $fix = 'tidy:autoload';
    4367                }
    4468
    … …  
    5074                                /* translators: 1: size, 2: number of settings */
    5175                                sprintf( __( 'WordPress loads %1$s of settings on every request (%2$s entries)', 'imzura-site-check' ), $this->kb( $kb ), number_format_i18n( $count ) ),
    52                                 __( 'This is read from the database before every page and every admin screen, and no page cache can skip it. Most of it usually belongs to a few plugins, some of them long removed. The largest entries are listed below.', 'imzura-site-check' ),
    53                                 $facts
     76                                $detail,
     77                                $facts,
     78                                $fix
    5479                        ),
    5580                );
    5681        }
     82
     83        private function read( array $pages ) {
     84                $read = null;
     85
     86                foreach ( $pages as $page ) {
     87                        if ( empty( $page['pending'] ) && isset( $page['options'] ) && is_array( $page['options'] ) ) {
     88                                $read = (array) $read + array_fill_keys( array_map( 'strval', $page['options'] ), true );
     89                        }
     90                }
     91
     92                return $read;
     93        }
     94
     95        private function owner( array $owner ) {
     96                if ( 'core' === $owner['kind'] ) {
     97                        return __( 'WordPress', 'imzura-site-check' );
     98                }
     99
     100                if ( 'shared' === $owner['kind'] ) {
     101                        return __( 'temporary data or a library several plugins share', 'imzura-site-check' );
     102                }
     103
     104                if ( 'unknown' === $owner['kind'] ) {
     105                        return __( 'owner not known', 'imzura-site-check' );
     106                }
     107
     108                $name = 'theme' === $owner['kind']
     109                        /* translators: %s: theme name */
     110                        ? sprintf( __( 'the %s theme', 'imzura-site-check' ), $owner['name'] )
     111                        : $owner['name'];
     112
     113                if ( 'inactive' === $owner['state'] ) {
     114                        /* translators: %s: plugin or theme name */
     115                        return sprintf( __( '%s, not active', 'imzura-site-check' ), $name );
     116                }
     117
     118                /* translators: %s: plugin or theme name */
     119                return 'removed' === $owner['state'] ? sprintf( __( '%s, removed', 'imzura-site-check' ), $name ) : $name;
     120        }
    57121}
  • imzura-site-check/trunk/includes/checks/class-images.php

    r3797325 r3801444  
    7272                                }
    7373
     74                                $pushed = array();
     75
     76                                foreach ( isset( $look['pushers'] ) && is_array( $look['pushers'] ) ? array_slice( $look['pushers'], 0, 2 ) : array() as $element ) {
     77                                        $pushed[] = self::line( $element, 80 );
     78                                }
     79
    7480                                $shifts[] = array(
    7581                                        'label' => $page['label'],
    7682                                        'shift' => $shift,
    7783                                        'what'  => array_filter( $what ),
     84                                        'by'    => array_filter( $pushed ),
    7885                                );
    7986                        }
    … …  
    164171
    165172                        foreach ( $shifts as $shift ) {
     173                                if ( $shift['by'] ) {
     174                                        /* translators: 1: page name, 2: layout shift score, 3: the elements added while the page loaded, 4: the elements they pushed */
     175                                        $facts[] = sprintf( __( '%1$s: %2$s, %3$s was added while the page loaded and pushed %4$s down', 'imzura-site-check' ), $shift['label'], number_format_i18n( $shift['shift'], 2 ), implode( ', ', $shift['by'] ), $shift['what'] ? implode( ', ', $shift['what'] ) : __( 'the content', 'imzura-site-check' ) );
     176                                        continue;
     177                                }
     178
    166179                                $facts[] = $shift['what']
    167180                                        /* translators: 1: page name, 2: layout shift score, 3: the elements that moved */
  • imzura-site-check/trunk/includes/class-admin-page.php

    r3797865 r3801444  
    5555                                'rescue' => esc_url_raw( Fixer::rescue_url() ),
    5656                                'tidy'   => Tidy::state(),
     57                                'spare'  => Options::state(),
    5758                                'review' => array(
    5859                                        'due' => ! get_user_meta( get_current_user_id(), Rest::REVIEW_META, true ),
    … …  
    8687                                        'tidy_forgotten' => __( 'The copy of the old revisions is deleted.', 'imzura-site-check' ),
    8788                                        'tidy_failed'    => __( 'That did not work. Nothing was removed without a copy; reload the page and try again.', 'imzura-site-check' ),
     89                                        'spare_go'       => __( 'Stop loading them on every request', 'imzura-site-check' ),
     90                                        /* translators: 1: number of settings, 2: size, 3: date and time */
     91                                        'spare_done'     => __( '%1$s settings (%2$s) of plugins and themes that are not active no longer load on every request, since %3$s. They are still in the database.', 'imzura-site-check' ),
     92                                        'spare_undo'     => __( 'Load them on every request again', 'imzura-site-check' ),
     93                                        /* translators: %s: number of settings */
     94                                        'spare_back'     => __( '%s settings load on every request again.', 'imzura-site-check' ),
     95                                        'spare_failed'   => __( 'That did not work, and nothing was changed. Reload the page and try again.', 'imzura-site-check' ),
    8896                                        /* translators: %s: a size in megabytes, e.g. 1.4 */
    8997                                        'mb'             => __( '%s MB', 'imzura-site-check' ),
  • imzura-site-check/trunk/includes/class-fixer.php

    r3797325 r3801444  
    2424                $fixes = array();
    2525
    26                 foreach ( apply_filters( 'speed_doctor_fixes', array( new Fixes\Cart_Script(), new Fixes\WooCommerce_Files(), new Fixes\Contact_Form_7(), new Fixes\Heavy_Images(), new Fixes\Lcp_Image(), new Fixes\Image_Sizes(), new Fixes\Local_Fonts(), new Fixes\Minify_Styles(), new Fixes\Minify_Scripts(), new Fixes\Emoji(), new Fixes\Visitor_Heartbeat(), new Fixes\Jquery_Migrate(), new Fixes\Defer_Scripts(), new Fixes\Video_Facade() ) ) as $fix ) {
     26                foreach ( apply_filters( 'speed_doctor_fixes', array( new Fixes\Cart_Script(), new Fixes\WooCommerce_Files(), new Fixes\Contact_Form_7(), new Fixes\Heavy_Images(), new Fixes\Lcp_Image(), new Fixes\Image_Sizes(), new Fixes\Local_Fonts(), new Fixes\Minify_Styles(), new Fixes\Minify_Scripts(), new Fixes\Emoji(), new Fixes\Visitor_Heartbeat(), new Fixes\Jquery_Migrate(), new Fixes\Defer_Scripts(), new Fixes\Video_Facade(), new Fixes\Map_Facade() ) ) as $fix ) {
    2727                        if ( $fix instanceof Fix ) {
    2828                                $fixes[ $fix->id() ] = $fix;
  • imzura-site-check/trunk/includes/class-plugin.php

    r3797416 r3801444  
    5050                        new Checks\Environment(),
    5151                        new Checks\Delivery(),
     52                        new Checks\Cache_Blockers(),
    5253                        new Checks\Errors(),
    5354                        new Checks\Images(),
    … …  
    5556                        new Checks\Fonts(),
    5657                        new Checks\Scripts(),
     58                        new Checks\Interactions(),
    5759                        new Checks\Idle_Styles(),
    5860                        new Checks\Code_Time(),
  • imzura-site-check/trunk/includes/class-probe.php

    r3797325 r3801444  
    2424
    2525        private static $errors = array();
     26
     27        private static $stranger = false;
     28
     29        private static $nocache = false;
    2630
    2731        public static function targets() {
    … …  
    232236                }
    233237
    234                 header_register_callback(
    235                         static function () {
    236                                 header_remove( 'Set-Cookie' );
    237                         }
    238                 );
     238                self::$stranger = true;
     239
     240                header_register_callback( array( __CLASS__, 'sending' ) );
    239241
    240242                // phpcs:ignore WordPress.WP.AlternativeFunctions.rand_seeding_mt_srand -- a fixed seed is the point; it applies to this test request only.
    … …  
    258260                                        'marks'  => isset( self::$trial['marks'] ) ? array_values( (array) self::$trial['marks'] ) : array(),
    259261                                        'scan'   => ! empty( self::$trial['scan'] ),
     262                                        'tap'    => ! empty( self::$trial['tap'] ),
    260263                                )
    261264                        ) . ';' . file_get_contents( SPEED_DOCTOR_DIR . 'assets/probe.js' ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a file of this plugin, only read.
    … …  
    330333        }
    331334
     335        public static function sending() {
     336                Profiler::seal();
     337
     338                if ( self::$stranger ) {
     339                        header_remove( 'Set-Cookie' );
     340                }
     341
     342                if ( self::$nocache ) {
     343                        self::$nocache = false;
     344                        nocache_headers();
     345                }
     346        }
     347
    332348        public static function buffer() {
    333                 nocache_headers();
     349                if ( self::$stranger && Profiler::on() ) {
     350                        self::$nocache = true;
     351                } else {
     352                        nocache_headers();
     353                }
     354
    334355                add_action( 'wp_finalized_template_enhancement_output_buffer', array( __CLASS__, 'keep' ) );
    335356        }
    … …  
    372393                $page['saved']     = Fixer::savings();
    373394                $page['manifest']  = Pipeline::manifest();
     395                $page['cache']     = Profiler::on() && self::$stranger ? Profiler::cache() : null;
     396                $page['options']   = Profiler::options_read();
    374397                $page['context']   = array(
    375398                        'store_page'   => function_exists( 'is_woocommerce' ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() ),
    … …  
    378401                        'has_store'    => ! $seen || Fixes\WooCommerce_Files::in_page( $html ),
    379402                );
     403
     404                if ( self::$nocache && ! headers_sent() ) {
     405                        self::$nocache = false;
     406                        nocache_headers();
     407                }
    380408
    381409                set_transient( self::PREFIX . self::$token, $page, self::LIFE );
  • imzura-site-check/trunk/includes/class-profiler.php

    r3797325 r3801444  
    2727
    2828        private static $cost = 0;
     29
     30        private static $sig = '';
     31
     32        private static $session = null;
     33
     34        private static $cookies = array();
     35
     36        private static $control = array( '', '' );
     37
     38        private static $sealed = null;
     39
     40        private static $read = array();
    2941
    3042        public static function watch() {
    … …  
    5870                add_action( 'do_meta_boxes', array( __CLASS__, 'boxes' ), PHP_INT_MAX );
    5971
     72                foreach ( array_keys( Options::big() ) as $name ) {
     73                        add_filter( 'option_' . $name, array( __CLASS__, 'read' ), PHP_INT_MAX, 2 );
     74                }
     75
     76                self::notice( '' );
    6077                self::mark();
    6178        }
    … …  
    110127        }
    111128
    112         public static function loaded() {
     129        public static function loaded( $plugin = '' ) {
     130                $began = hrtime( true );
     131
     132                self::notice( is_string( $plugin ) && '' !== $plugin ? Probe::owner_of_path( $plugin ) : '' );
     133
    113134                if ( isset( $GLOBALS['wp_filter']['plugins_loaded'] ) && $GLOBALS['wp_filter']['plugins_loaded'] instanceof \WP_Hook ) {
    114                         $began = hrtime( true );
    115135                        self::mark_hook( $GLOBALS['wp_filter']['plugins_loaded'] );
    116                         self::$cost += hrtime( true ) - $began;
    117                 }
     136                }
     137
     138                self::$cost += hrtime( true ) - $began;
     139        }
     140
     141        public static function seal() {
     142                if ( ! self::$on || null !== self::$sealed ) {
     143                        return;
     144                }
     145
     146                $began = hrtime( true );
     147
     148                self::notice( '' );
     149
     150                $name    = function_exists( 'session_name' ) ? (string) session_name() : '';
     151                $started = self::session() ? ( is_string( self::$session ) ? self::$session : '' ) : null;
     152                $cookies = array();
     153                $control = '';
     154
     155                foreach ( headers_list() as $line ) {
     156                        list( $header, $value ) = self::split( $line );
     157
     158                        if ( 'set-cookie' === $header ) {
     159                                $cookie = self::cookie( $value );
     160
     161                                if ( '' !== $name && $cookie === $name ) {
     162                                        if ( null === $started ) {
     163                                                $started = isset( self::$cookies[ $cookie ] ) ? self::$cookies[ $cookie ] : '';
     164                                        }
     165                                } elseif ( '' !== $cookie && ! isset( $cookies[ $cookie ] ) && count( $cookies ) < 10 ) {
     166                                        $cookies[ $cookie ] = array(
     167                                                'name'  => $cookie,
     168                                                'owner' => isset( self::$cookies[ $cookie ] ) ? self::$cookies[ $cookie ] : '',
     169                                        );
     170                                }
     171                        } elseif ( 'cache-control' === $header ) {
     172                                $control = $value;
     173                        }
     174                }
     175
     176                self::$sealed = array(
     177                        'session' => null !== $started ? array(
     178                                'name'  => '' !== $name ? $name : 'PHPSESSID',
     179                                'owner' => $started,
     180                        ) : null,
     181                        'cookies' => array_values( $cookies ),
     182                        'control' => preg_match( '/\b(no-store|no-cache|private)\b|\bmax-age=0\b/i', $control ) ? array(
     183                                'value' => $control,
     184                                'owner' => $control === self::$control[0] ? self::$control[1] : '',
     185                        ) : null,
     186                );
     187
     188                self::$cost += hrtime( true ) - $began;
     189        }
     190
     191        public static function read( $value, $name = '' ) {
     192                self::$read[ (string) $name ] = true;
     193
     194                return $value;
     195        }
     196
     197        public static function options_read() {
     198                return self::$on ? array_keys( self::$read ) : null;
     199        }
     200
     201        public static function cache() {
     202                self::seal();
     203
     204                return is_array( self::$sealed ) ? self::$sealed : array();
     205        }
     206
     207        private static function notice( $owner ) {
     208                if ( null !== self::$sealed ) {
     209                        return;
     210                }
     211
     212                $session = self::session();
     213                $lines   = headers_list();
     214                $sig     = ( $session ? '1' : '0' ) . implode( "\n", $lines );
     215
     216                if ( $sig === self::$sig ) {
     217                        return;
     218                }
     219
     220                self::$sig = $sig;
     221
     222                if ( self::SELF === $owner ) {
     223                        return;
     224                }
     225
     226                if ( $session && null === self::$session ) {
     227                        self::$session = $owner;
     228                }
     229
     230                foreach ( $lines as $line ) {
     231                        list( $header, $value ) = self::split( $line );
     232
     233                        if ( 'set-cookie' === $header ) {
     234                                $cookie = self::cookie( $value );
     235
     236                                if ( '' !== $cookie && ! isset( self::$cookies[ $cookie ] ) ) {
     237                                        self::$cookies[ $cookie ] = $owner;
     238                                }
     239                        } elseif ( 'cache-control' === $header && $value !== self::$control[0] ) {
     240                                self::$control = array( $value, $owner );
     241                        }
     242                }
     243        }
     244
     245        private static function session() {
     246                return function_exists( 'session_status' ) && PHP_SESSION_ACTIVE === session_status();
     247        }
     248
     249        private static function split( $line ) {
     250                $parts = explode( ':', (string) $line, 2 );
     251
     252                return array( strtolower( trim( $parts[0] ) ), isset( $parts[1] ) ? trim( $parts[1] ) : '' );
     253        }
     254
     255        private static function cookie( $value ) {
     256                return trim( (string) strtok( (string) $value, '=;' ) );
    118257        }
    119258
    … …  
    217356                $top = count( self::$stack ) - 1;
    218357
     358                self::notice( $top >= 0 ? self::$stack[ $top ][0] : '' );
     359
    219360                while ( $top >= 0 && self::$stack[ $top ][1] >= $depth ) {
    220361                        self::close( $now );
  • imzura-site-check/trunk/includes/class-rest.php

    r3797325 r3801444  
    4242                                                                                'stranger' => true,
    4343                                                                                'scan'     => true,
     44                                                                                'tap'      => true,
    4445                                                                        )
    4546                                                                ),
    … …  
    114115                register_rest_route(
    115116                        self::SPACE,
     117                        '/tidy/autoload/(?P<step>run|undo)',
     118                        array(
     119                                'methods'             => 'POST',
     120                                'permission_callback' => array( __CLASS__, 'allowed' ),
     121                                'callback'            => array( __CLASS__, 'autoload' ),
     122                        )
     123                );
     124
     125                register_rest_route(
     126                        self::SPACE,
    116127                        '/fixes/(?P<id>[a-z0-9-]+)/(?P<step>trial|prepare|verdict|off)',
    117128                        array(
    … …  
    136147        }
    137148
     149        public static function autoload( \WP_REST_Request $request ) {
     150                $result = 'run' === $request['step'] ? Options::run() : Options::undo();
     151
     152                return is_wp_error( $result ) ? $result : rest_ensure_response( array( 'autoload' => $result ) );
     153        }
     154
    138155        public static function fix( \WP_REST_Request $request ) {
    139156                $fixes = Fixer::all();
  • imzura-site-check/trunk/includes/fixes/class-contact-form-7.php

    r3797325 r3801444  
    1111final class Contact_Form_7 extends Fix {
    1212
    13         const SEEN    = 'speed_doctor_form_page';
    14         const TAGS    = array( 'contact-form-7', 'contact-form' );
    15         const STYLES  = array( 'contact-form-7', 'contact-form-7-rtl', 'jquery-ui-smoothness', 'astra-contact-form-7' );
    16         const EARLY   = array( 'cloudflare-turnstile' );
    17         const SCRIPTS = array( 'contact-form-7', 'contact-form-7-html5-fallback', 'wpcf7-recaptcha' );
     13        const SEEN     = 'speed_doctor_form_page';
     14        const TAGS     = array( 'contact-form-7', 'contact-form' );
     15        const STYLES   = array( 'contact-form-7', 'contact-form-7-rtl', 'jquery-ui-smoothness', 'astra-contact-form-7' );
     16        const EARLY    = array( 'cloudflare-turnstile' );
     17        const SCRIPTS  = array( 'contact-form-7', 'contact-form-7-html5-fallback', 'wpcf7-recaptcha' );
     18        const BUILDERS = array( '_elementor_data', '_fl_builder_data', '_bricks_page_content_2', 'ct_builder_shortcodes' );
    1819
    1920        private $built = false;
    … …  
    3738        public function unavailable() {
    3839                return defined( 'WPCF7_VERSION' ) ? '' : __( 'Contact Form 7 is not active on this site.', 'imzura-site-check' );
    39         }
    40 
    41         public function untestable() {
    42                 return $this->targets() ? '' : __( 'No page with a form was found to test on. Open the page that shows your form once, then try again.', 'imzura-site-check' );
    4340        }
    4441
    … …  
    6057                );
    6158                $added   = (int) get_option( self::SEEN, 0 );
     59                $written = $written ? $written : $this->in_builder();
    6260
    6361                if ( $written ) {
    … …  
    196194        }
    197195
     196        private function in_builder() {
     197                $clauses = array( 'relation' => 'OR' );
     198
     199                foreach ( self::BUILDERS as $key ) {
     200                        $clauses[] = array(
     201                                'key'     => $key,
     202                                'value'   => 'contact-form',
     203                                'compare' => 'LIKE',
     204                        );
     205                }
     206
     207                return get_posts(
     208                        array(
     209                                'post_type'   => 'any',
     210                                'post_status' => 'publish',
     211                                'numberposts' => 1,
     212                                'fields'      => 'ids',
     213                                // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- once, when the fix is tried from the admin screen.
     214                                'meta_query'  => $clauses,
     215                        )
     216                );
     217        }
     218
    198219        private function expected() {
    199220                $post = is_singular() ? get_queried_object() : null;
  • imzura-site-check/trunk/readme.txt

    r3797865 r3801444  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.5.0
     7Stable tag: 1.6.0
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    3939* Speed settings of well-known plugins that are off: Elementor (Inline Font Icons, CSS Print Method, optimized image loading, lazy background images, local Google Fonts and their font-display), Formidable Forms styles on every page, Wordfence logging every visit, and the local Google Fonts setting of Astra, Kadence, OceanWP and Spectra (or GeneratePress font-display) when their fonts come from Google. This plugin only reads these settings and names them as each plugin's screen does
    4040* Housekeeping: the PHP error log (whether strangers can download it, its size, the plugins that fill it), backup and archive files left in wp-content, the largest database tables, plugins that are installed but switched off, and two SEO plugins active at once
    41 * Settings WordPress loads on every request (autoloaded options) and the largest of them
     41* Slow taps (Interaction to Next Paint): after the page has loaded, the check taps menus, buttons and tabs (never a link or a form, and with the network held back) and names the plugin or theme whose code made the visitor wait, and scripts that keep the browser busy after the page has loaded
     42* Pages built from too many elements (more than 1,400), how many of them are hidden at phone width, and the largest parts of each page
     43* Pages that no server or CDN cache can keep: the plugin or theme that gives every first-time visitor a cookie or a PHP session, or sends a no-store, no-cache or private header (the cart and the checkout are left out)
     44* Settings WordPress loads on every request (autoloaded options): the largest of them with the plugin or theme each belongs to, active, switched off or removed, and a button that stops loading the ones left behind by plugins and themes that are not active (they stay in the database, and it can be undone)
    4245* Scheduled jobs that have fallen behind, including the Action Scheduler queue
    4346* WooCommerce: order storage, sessions that pile up, the cart script running outside the shop
    … …  
    5861* **Minify stylesheets (CSS)** and **Minify scripts (JavaScript)**, two separate fixes. The spaces, line breaks and comments come out of your theme's and plugins' own files, and a smaller copy is sent instead, under the same handle. Files that are minified already, files from other sites and code written into the page are left alone, and so is a file that would not get at least 5% smaller. Addresses inside stylesheets are rewritten, so fonts and pictures still load. If a script stops working once minified, the trial sees the error in that file, sends it as it is from then on and tests again; the fix is kept only if the pages then work, and the screen shows how many files are sent as they are.
    5962* **Leave out the emoji script.** WordPress adds a script and styles to every page so that very old browsers can show emoji as pictures. Browsers in use today show emoji themselves.
     63* **Stop Heartbeat calls from visitors.** When a plugin loads WordPress Heartbeat on public pages, every open tab calls admin-ajax.php again and again, past any page cache. Before the trial this plugin calls admin-ajax.php itself as a visitor and looks at what answers Heartbeat there; only when nothing does is the Heartbeat file left out, with a stand-in that keeps the scripts that asked for it working. Logged-in users keep Heartbeat.
    6064* **Load jQuery without jQuery Migrate.** Migrate only helps code written for old versions of jQuery. If a script on your site still needs it, the test sees it fail and the fix is not kept.
    6165* **Load scripts in the head with defer.** Scripts in the head of the page make the browser wait before it shows anything. With the fix they download alongside the page and run once it is read, in the same order as before. jQuery is left as it is, because code written into pages often needs it right away. Needs WordPress 6.3 or newer.
    6266* **Show YouTube videos as a picture until play is pressed.** An embedded YouTube video loads the whole player as soon as the page opens, even for visitors who never watch it. With the fix the video shows its picture, from YouTube, and a play button in the same place and size, and the player loads when the button is pressed. Needs WordPress 6.9 or newer.
     67* **Show Google Maps as a button until the visitor asks for the map.** An embedded Google Map loads its whole map viewer as soon as the page opens, even for visitors who never look at it. With the fix the map keeps its place and size and shows a button; the map loads when the button is pressed. Needs WordPress 6.9 or newer.
    6368
    6469The screen has a tab for each kind of fix (CSS & JS, Images, Plugins), one for the check, and one for your page cache: which one is active, a test that opens the home page as a new visitor, and a button that clears it.
    … …  
    115120Yes. The people behind this plugin fix slow WordPress and WooCommerce sites for a fixed price, on a copy of the site first, with a before-and-after measurement: [imzura.com](https://imzura.com/services/wordpress-speed-optimization?utm_source=imzura-site-check&utm_medium=readme). The plugin works the same whether you ask or not.
    116121
     122= Site Health says "Autoloaded options could affect performance". Can this plugin help? =
     123
     124Yes. The check lists the largest settings WordPress loads on every request and the plugin or theme each one belongs to. Settings left behind by plugins and themes that are switched off or removed, and not read on any page the check opened, can be taken off the every-request list with one button. Nothing is deleted, a plugin that comes back still finds its settings, and the button next to it puts everything back.
     125
     126= My host or Cloudflare should cache my pages, but every visit is a miss. Why? =
     127
     128Run the check: it names the plugin or theme that gives every first-time visitor a cookie or a PHP session, or sends a header that tells caches not to keep the page. Server and CDN caches do not keep such pages by default. Look in that plugin's settings for a way to set the cookie only when it is needed, or ask its author.
     129
    117130= Does it replace my cache plugin? =
    118131
    … …  
    178191
    179192== Changelog ==
     193
     194= 1.6.0 =
     195* New check: slow taps (Interaction to Next Paint). After the page has loaded, the check taps up to five menus, buttons or tabs and names the plugin or theme whose click code made the visitor wait, and scripts that keep the browser busy after load.
     196* New check: pages built from more than 1,400 elements, with how many are hidden at phone width and the largest parts.
     197* New check: pages that no server or CDN cache can keep, with the plugin or theme that gives every first-time visitor a cookie or a PHP session, or marks the page no-store, no-cache or private.
     198* The autoloaded settings finding names the plugin or theme behind each large entry, and a button stops loading the entries of plugins and themes that are not active or were removed (undo puts them back). Needs WordPress 6.4 or newer.
     199* New fix: Google Maps embeds show a button in the same place and size, and the map loads when the visitor asks for it.
     200* A layout shift now names what was added while the page loaded and pushed the content down, not only what moved.
     201* The Contact Form 7 fix can be tried on a site where no page shows a form, and it finds forms kept in page-builder data (Elementor, Beaver Builder, Bricks, Oxygen).
    180202
    181203= 1.5.0 =
  • imzura-site-check/trunk/uninstall.php

    r3797325 r3801444  
    1515delete_option( 'speed_doctor_fonts' );
    1616delete_option( 'speed_doctor_tidy' );
     17delete_option( 'speed_doctor_autoload_spare' );
     18delete_option( 'speed_doctor_autoload_off' );
    1719delete_metadata( 'user', 0, 'speed_doctor_review', '', true );
    1820
Note: See TracChangeset for help on using the changeset viewer.