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

Critical CSS doesn't respect dependency order #22

Open
johnbillion opened this issue Aug 4, 2021 · 0 comments
Open

Critical CSS doesn't respect dependency order #22

johnbillion opened this issue Aug 4, 2021 · 0 comments

Comments

@johnbillion
Copy link

When more than one critical CSS file is registered (for example, one from a parent theme and one from a child theme) the dependencies are not respected. They get output in the order in which add_asset() is called, not according to their dependencies.

In the code below, critical-first should be output first because it's a dependency of critical-second, but critical-second gets output first because that's the order in which add_asset() is called.

$styles = [
    [
        'condition'   => 'global',
        'deps'        => [
            'critical-first',
        ],
        'handle'      => 'critical-second',
        'load_hook'   => 'am_critical',
        'load_method' => 'inline',
        'src'         => MY_PATH . '/critical-second.css',
        'version'     => 1,
    ],
    [
        'condition'   => 'global',
        'deps'        => [],
        'handle'      => 'critical-first',
        'load_hook'   => 'am_critical',
        'load_method' => 'inline',
        'src'         => MY_PATH . '/critical-first.css',
        'version'     => 1,
    ],

];

array_map( [ \Asset_Manager_Styles::instance(), 'add_asset' ], $styles );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant