1. Go to this page and download the library: Download jbzoo/assets 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/ */
jbzoo / assets example snippets
use JBZoo\Assets\Manager;
use JBZoo\Path\Path;
// Initialize path resolver and asset manager
$path = new Path();
$path->set('assets', '/path/to/your/assets');
$manager = new Manager($path);
// Register and queue assets
$manager
->register('jquery', 'assets/js/jquery.js')
->register('bootstrap-css', 'assets/css/bootstrap.css')
->register('app', 'assets/js/app.js', ['jquery']) // depends on jquery
->add('bootstrap-css')
->add('app');
// Build assets with dependency resolution
$assets = $manager->build();
// Output: Array with organized asset types
// $assets['js'] contains JavaScript files
// $assets['css'] contains CSS files
// jQuery must load before Bootstrap JavaScript
$manager
->register('jquery', 'assets/js/jquery.js')
->register('bootstrap-js', 'assets/js/bootstrap.js', ['jquery'])
->add('bootstrap-js'); // jQuery will be
$path = new Path();
$path->set('assets', '/var/www/assets');
$path->set('vendor', '/var/www/vendor');
$manager = new Manager($path);
// Use virtual paths
$manager->register('app', 'assets:js/app.js'); // Resolves to /var/www/assets/js/app.js
$manager->register('lib', 'vendor:lib/script.js'); // Resolves to /var/www/vendor/lib/script.js
// Relative to current working directory
$manager->register('local', 'js/local.js');
// Absolute path
$manager->register('system', '/usr/share/js/system.js');
$manager = new Manager($path, ['debug' => true]);
// Or set later
$manager->setParam('debug', true);
$manager = new Manager($path, ['strict_mode' => true]);
// Throws exceptions for missing files
$manager->register('missing', 'assets/js/missing.js');
$manager->add('missing');
$manager->build(); // Exception thrown
$assets = $manager->build();
// Generate HTML tags
foreach ($assets['css'] as $cssFile) {
echo '<link rel="stylesheet" href="' . $cssFile . '">' . PHP_EOL;
}
foreach ($assets['js'] as $jsFile) {
echo '<script src="' . $jsFile . '"></script>' . PHP_EOL;
}
// Include inline styles
if (!empty($assets['css_code'])) {
echo '<style>' . implode("\n", $assets['css_code']) . '</style>';
}
// Include inline scripts
if (!empty($assets['js_code'])) {
echo '<script>' . implode("\n", $assets['js_code']) . '</script>';
}
// Register a collection of related assets
$manager->add('ui-components', [
'assets/css/buttons.css',
'assets/css/modals.css',
'assets/js/components.js'
]);