PHP code example of roumen / asset

1. Go to this page and download the library: Download roumen/asset 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/ */

    

roumen / asset example snippets


use Rumenx\Assets\Asset;

// Add assets
Asset::add('style.css');
Asset::add('theme.less');
Asset::add('app.js');
Asset::add(['extra.js', 'extra2.js'], 'footer');

// Add inline style or script
Asset::addStyle('body { background: #fafafa; }');
Asset::addScript('console.log("Hello!");');

// Output in your template
Asset::css();      // <link rel="stylesheet" ...>
Asset::less();     // <link rel="stylesheet/less" ...>
Asset::js();       // <script src=...></script>
Asset::styles();   // <style>...</style>
Asset::scripts();  // <script>...</script>

// Use cachebuster (file-based)
Asset::setCachebuster(__DIR__.'/cache.json');

// Use cachebuster (function-based)
Asset::setCacheBusterGeneratorFunction(function($file) {
    return md5($file);
});

// Custom domain or prefix
Asset::setDomain('https://cdn.example.com/');
Asset::setPrefix('X-');

    Rumenx\Assets\Laravel\AssetServiceProvider::class,
    

    use Rumenx\Assets\Asset;

    Asset::add('main.css');
    Asset::add('main.js');

    // In your Blade template
    {!! Asset::css() !!}
    {!! Asset::js() !!}
    

    $assets = app('assets');
    $assets::add('custom.js');
    

    // config/bundles.php
    return [
        Rumenx\Assets\Symfony\AssetBundle::class => ['all' => true],
    ];
    

    use Rumenx\Assets\Asset;

    Asset::add('main.css');
    Asset::add('main.js');

    // In a Twig template
    dump(Asset::css());
    dump(Asset::js());
    
bash
composer