Which Smarty blocks are overwritten by the CDN plugin?

Please note that this help center article is only valid for the Shopware 5 CDN plugin.


CSS

The Shopware 5 plugin overwrites the Smarty block for global CSS delivery:

# /Resources/Views/frontend/index/index.tpl

{block name="frontend_index_header_css_screen"}

{* creoline CDN *}

{/block}



JS

The Shopware 5 plugin overwrites the Smarty block for global JS delivery:

# /Resources/Views/frontend/index/index.tpl and /Resources/Views/frontend/index/header.tpl

{block name="frontend_index_header_javascript_modernizr_lib"}

{* creoline CDN *}

{/block}

{block name="frontend_index_header_javascript_jquery_lib"}

{* creoline CDN *}

{/block}



Why can't additional plugins also overwrite the block?

In order for the CDN to function properly and deliver all CSS files and JavaScript files via CDN, all CSS and JS files used must be correctly integrated via the Media Manager.


Plugin developers often use the Smarty blocks to provide additional CSS or JavaScript files instead of loading them via the plugin system. In this case, the CDN plugin cannot detect the files and therefore cannot provide a CDN version.


In this case, please inform the respective plugin manufacturer and ask them to integrate CSS and JS files via the Shopware 5 plugin event system.



Provide CSS and JS via the plugin system


Shopware events for the registration of Less (CSS) and JavaScript:

Theme_Compiler_Collect_Plugin_Less

Theme_Compiler_Collect_Plugin_Javascript


Example implementation for Shopware 5 plugin

public static function getSubscribedEvents() {
    return [
        'Theme_Compiler_Collect_Plugin_Less' => 'addLessFiles',
        'Theme_Compiler_Collect_Plugin_Javascript' => 'addJavaScriptFiles',
    ];
}

<br>

public function addLessFiles()
{
    return new LessDefinition(
        [],
        [
            __DIR__ . '/Views/frontend/_public/src/less/example.less'
        ]
    );
}

public function addJavaScriptFiles()
{
    return new ArrayCollection([
        __DIR__ . '/Views/frontend/_public/src/js/example.js'
    ]);

}