1. Go to this page and download the library: Download nedarta/php-assetopt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nedarta / php-assetopt example snippets
use nedarta\AssetOpt\Minifier;
$compressedCss = (new Minifier)->run($css);
use nedarta\AssetOpt\JsStrip;
$compressedJs = (new JsStrip)->compress($js);
use nedarta\AssetOpt\ImportResolver;
use nedarta\AssetOpt\Minifier;
// css with @import at-rules
$css = file_get_contents('path/to/styles.css');
// resolve @import at-rules: $baseDir for relative @import urls
$css = (new ImportResolver)->resolve($css, 'path/to');
// minify resolved css
$compressedCss = (new Minifier)->run($css);
use nedarta\AssetOpt\Minifier as CSSmin;
$cssmin = new Minifier([
/* Raise PHP limits */
'raise_php_limits' => true
]);
$cssmin->setMaxExecutionTime(30); // Set maximum execution time to 30 seconds by default
$cssmin->setPcreBacktrackLimit(2000000); // Set PCRE backtrack limit to 2 x 2 by default
$cssmin->setPcreRecursionLimit(500000); // Set PCRE recursion limit to 5 x 0.5 by default
$cssmin->keepSourceMapComment(); // Keeps sourcemap special comment in the output by default
$cssmin->removeImportantComments(); // Removes !important comments in the output by default
$cssmin->setLineBreakPosition(500); // Set line break position
$compressedCss = $cssmin->run($css);
/**
* Simple Yii2 AssetBundle with minification of contents
* of its $css and $js files in the production environment.
*/
class AppAsset extends AssetBundle
{
public $sourcePath = '@app/assets';
public $css = [
'css/app.css',
'https://fonts.googleapis.com/css?family=PT+Serif:400,700,400italic,700italic',
];
public $js = [
'js/app.js',
];
public $depends = [
\yii\web\JqueryAsset::class,
\yii\bootstrap\BootstrapAsset::class,
];
...
}