Support » Plugin: Asset CleanUp: Page Speed Booster » Get list of preloaded and optimised assets

  • Resolved Mos Craciun

    (@furioussnail)


    Hello.
    Does the plugin’s API offer an accessible way to get a list of preloaded and optimised (minified and/or combined) assets?
    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gabe Livan

    (@gabelivan)

    @furioussnail I’m not sure what you really mean here. Are you referring to a way of extracting from an URL the list of all the preloaded (e.g. via LINK rel=”preload”) assets and the minified/combined ones (e.g. the references from /wp-content/cache/ directory)? If that’s what you want, then Asset CleanUp doesn’t have this functionality.

    Thread Starter Mos Craciun

    (@furioussnail)

    This is how I got it in the end:

    
        $preloadsListJson = get_option(WPACU_PLUGIN_ID.'_global_data');
    
        if ($preloadsListJson) {
            $preloadsList = @json_decode($preloadsListJson, true);
    
            // Issues with decoding the JSON file? Return an empty list
            if (Misc::jsonLastError() !== JSON_ERROR_NONE) {
                return;
            }
    
            $fromLocation = ($GLOBALS['wpacu_from_location_inc'] % 2) ? 'db' : 'disk';
    
            // Are new positions set for styles and scripts?
            if (isset($preloadsList['styles']['preloads']) && ! empty($preloadsList['styles']['preloads'])) {
                foreach ($preloadsList['styles']['preloads'] as $key => $value) {
                    $handleDbStr = md5($key);
    
                    $transientName = 'wpacu_css_optimize_'.$handleDbStr;
                    $transientFile = @json_decode(
                        \WpAssetCleanUp\OptimiseAssets\OptimizeCommon::getTransient($transientName, $fromLocation),
                        true
                    );
                }
            }
    
            if (isset($preloadsList['scripts']['preloads']) && ! empty($preloadsList['scripts']['preloads'])) {
                foreach ($preloadsList['scripts']['preloads'] as $key => $value) {
                    $handleDbStr = md5($key);
    
                    $transientName = 'wpacu_js_optimize_'.$handleDbStr;
                    $transientFile = @json_decode(
                        \WpAssetCleanUp\OptimiseAssets\OptimizeCommon::getTransient($transientName, $fromLocation),
                        true
                    );
    
                }
            }
        }
    
    • This reply was modified 3 months, 3 weeks ago by Mos Craciun.
    Plugin Author Gabe Livan

    (@gabelivan)

    @furioussnail I’m glad you found a way to retrieve the list. After checking the code, you should be fine in having it working without any problems as nothing significant will change in the near future that would affect the functionality of your PHP snippet. The option name will be the same in the database. Is there a reason you needed to use this snippet? Just curious 😉

    PS: Don’t forget to put a condition that will check if the plugin is active as whenever you will deactivate the plugin (even for debugging purposes), this snippet will trigger PHP errors for non-existent classes/methods.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.