Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets compressing with CDN link #15326

Open
phuczeero opened this issue Dec 10, 2017 · 3 comments
Open

Assets compressing with CDN link #15326

phuczeero opened this issue Dec 10, 2017 · 3 comments
Labels

Comments

@phuczeero
Copy link

I already checked all related issues but it doesn't work.

What steps will reproduce the problem?

My asset bundles:

class CdnAsset extends AssetBundle
{
    public $css = [
        '//fonts.googleapis.com/css?family=Roboto:300,400,500,700',
        '//fonts.googleapis.com/icon?family=Material+Icons',
    ];
}
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/app.scss',
    ];
    public $js = [
        'js/app.js',
    ];
    public $depends = [
        'webapp\assets\CdnAsset'
    ];
}

Using asset command and the config:

return [
    ...
    // The list of asset bundles to compress:
    'bundles' => [
        'webapp\assets\AppAsset',
    ],
    // Asset bundle for compression output:
    'targets' => [
        'all' => [
            'class' => 'yii\web\AssetBundle',
            'basePath' => '@webroot/assets',
            'baseUrl' => '@web/assets',
            'js' => 'all-{hash}.js',
            'css' => 'all-{hash}.css',
        ],
    ],
    // Asset manager configuration:
    'assetManager' => [
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
    ],
];

What is the expected result?

assets-prod.php

return [
    'all' => [
        'class' => 'yii\\web\\AssetBundle',
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
        'js' => [
            'all-22850b097b43acfaf56fbc35e29ee928.js',
        ],
        'css' => [
            'all-522b9bfa86a47cab88f42fd7fc8492b1.css',
        ],
        'sourcePath' => null,
        'depends' => ['webapp\\assets\\CdnAsset'],   // <---
    ],
    'webapp\\assets\\AppAsset' => [
        'sourcePath' => null,
        'js' => [],
        'css' => [],
        'depends' => [
            'webapp\\assets\\CdnAsset',
            'all',
        ],
    ],
];

What do you get instead?

return [
    'all' => [
        'class' => 'yii\\web\\AssetBundle',
        'basePath' => '@webroot/assets',
        'baseUrl' => '@web/assets',
        'js' => [
            'all-22850b097b43acfaf56fbc35e29ee928.js',
        ],
        'css' => [
            'all-522b9bfa86a47cab88f42fd7fc8492b1.css',
        ],
        'sourcePath' => null,
        'depends' => [],
    ],
    'webapp\\assets\\CdnAsset' => [
        'css' => [
            '//fonts.googleapis.com/css?family=Roboto:300,400,500,700',
            '//fonts.googleapis.com/icon?family=Material+Icons',
        ],
        'sourcePath' => null,
        'basePath' => null,
        'baseUrl' => null,
        'depends' => [],
        'js' => [],
        'jsOptions' => [],
        'cssOptions' => [],
        'publishOptions' => [],
        'class' => 'webapp\\assets\\CdnAsset',
    ],
    'webapp\\assets\\AppAsset' => [
        'sourcePath' => null,
        'js' => [],
        'css' => [],
        'depends' => [
            'webapp\\assets\\CdnAsset',
            'all',
        ],
    ],
];

Additional info

Q A
Yii version 2.0.12
PHP version 7.1
Operating system Apache/2.4.10 (Debian)
@phuczeero phuczeero changed the title Grouped assets compressing with CDN link Assets compressing with CDN link Dec 10, 2017
@samdark samdark added this to the 2.0.16 milestone Dec 10, 2017
@phuczeero
Copy link
Author

Please provide an option to set dependencies for compressed assets which depends on external sources, e.g: Fonts from google CDN

@samdark samdark added the type:bug Bug label Dec 18, 2017
@samdark samdark removed this from the 2.0.17 milestone Mar 20, 2019
@mgerasimchuk
Copy link

mgerasimchuk commented Jan 26, 2021

Also faced with this, very painful.

UPD:
Workaround for keeping all details in your asset bundle:

...
class NewsAsset extends AssetBundle {
    public $css = [
        'news.css',
    ];

    /** @inheritdoc */
    public static function register($view) {
        $view->registerJsFile('https://platform.twitter.com/widgets.js');
        return parent::register($view);
    }
}

With this approach, news.css will be minified, but widgets.js will only register on the page(without any compressing).
It covers my case - I don't want to minify external source(widgets.js), but I want to register this js file on my page.

@Mister-42
Copy link

Not an answer to your question, but https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons combines the css to one request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants