Important

You are browsing upcoming documentation for version 7.0 of OroCommerce, scheduled for release in 2026. Read the documentation for the latest LTS version to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Dynamic Assets 

Dynamic assets allow you to update assets during the application lifecycle, for example when an administrator configures your website. In such cases, the asset cache must be properly invalidated. Symfony does not provide this feature out-of-the-box, but the Asset Component can be extended to support it.

The following example demonstrates how to add dynamic versioning for any asset package.

For instance, assume that the acme asset package should use dynamic versioning.

  1. Register the package using Resources/config/oro/app.yml in your bundle or config/config.yml:

    framework:
        assets:
            packages:
                acme:
                    version_strategy: 'Oro\Bundle\AssetBundle\VersionStrategy\BuildVersionStrategy'
    
  2. Set |DynamicAssetVersionStrategy| for this package:

    namespace Acme\Bundle\DemoBundle;
    
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    
    use Oro\Bundle\UIBundle\DependencyInjection\Compiler\DynamicAssetVersionPass;
    
    class DemoBundle extends Bundle
    {
        #[\Override]
        public function build(ContainerBuilder $container): void
        {
            parent::build($container);
    
            $container->addCompilerPass(new DynamicAssetVersionPass('acme'));
        }
    }
    

    After this, the configuration is complete.

  3. Update the package version whenever assets change:

    namespace Acme\Bundle\DemoBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    
    class SomeController extends AbstractController
    {
        public function updateAction()
        {
         // ...
    
            /** @var Oro\Bundle\UIBundle\Asset\DynamicAssetVersionManager $assetVersionManager */
            $assetVersionManager = $this->container->get('oro_ui.dynamic_asset_version_manager');
            $assetVersionManager->updateAssetVersion('acme');
    
            // ...
        }
    
        public static function getSubscribedServices(): array
        {
            return array_merge(
                parent::getSubscribedServices(),
                ['oro_ui.dynamic_asset_version_manager' => DynamicAssetVersionManager::class]
            );
        }
    }
    

Once configured, your assets are used like any other asset, for example via the asset() Twig function:

{{ asset('test.js', 'acme') }}
{# the result may be something like this: test.js?version=123-2 #}
{# where #}
{# '123' is the static asset version #}
{# '2' is the dynamic asset version; this number increases each time you call $assetVersionManager->updateAssetVersion('acme') #}

Important: The package name must be passed to the asset() function. This tells Symfony that the asset belongs to your package and that the dynamic versioning strategy should be applied.