Jetpack::maybe_min_asset PHP Method

maybe_min_asset() public static method

Hooks onto plugins_url filter at priority 1, and accepts all 3 args.
public static maybe_min_asset ( $url, $path, $plugin )
    public static function maybe_min_asset($url, $path, $plugin)
    {
        // Short out on things trying to find actual paths.
        if (!$path || empty($plugin)) {
            return $url;
        }
        // Strip out the abspath.
        $base = dirname(plugin_basename($plugin));
        // Short out on non-Jetpack assets.
        if ('jetpack/' !== substr($base, 0, 8)) {
            return $url;
        }
        // File name parsing.
        $file = "{$base}/{$path}";
        $full_path = JETPACK__PLUGIN_DIR . substr($file, 8);
        $file_name = substr($full_path, strrpos($full_path, '/') + 1);
        $file_name_parts_r = array_reverse(explode('.', $file_name));
        $extension = array_shift($file_name_parts_r);
        if (in_array(strtolower($extension), array('css', 'js'))) {
            // Already pointing at the minified version.
            if ('min' === $file_name_parts_r[0]) {
                return $url;
            }
            $min_full_path = preg_replace("#\\.{$extension}\$#", ".min.{$extension}", $full_path);
            if (file_exists($min_full_path)) {
                $url = preg_replace("#\\.{$extension}\$#", ".min.{$extension}", $url);
            }
        }
        return $url;
    }
Jetpack