Skip to content

Improved the explanation of "version_strategy" option #7519

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,61 @@ version_strategy

**type**: ``string`` **default**: ``null``

The service id of the :doc:`asset version strategy </frontend/custom_version_strategy>`
applied to the assets.
The service id of the asset version strategy applied to the assets. In addition
to your own :doc:`custom asset version strategies </frontend/custom_version_strategy>`,
Symfony defines two services for its :ref:`built-in strategies <component-assets-versioning>`:
``assets.empty_version_strategy`` and ``assets.static_version_strategy``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets.static_version_strategy is not usable directly. It is an abstract service. So you cannot use it directly in version_strategy. If you want to use a static version, use the version setting (with a non-empty value) instead (which will create a child service configured with this version)


The ``assets.empty_version_strategy`` is useful to override the global asset
versioning strategy inside an asset package:

.. configuration-block::

.. code-block:: yaml

# app/config/config.yml
framework:
assets:
# this strategy is applied to every asset (including packages) ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this strategy is applied to all assets of the default package, and to all custom packages, unless they configure their own version or their own version strategy

version_strategy: 'app.asset.my_versioning_strategy'
packages:
foo_package:
# ... except if a package explicitly uses the empty strategy
version_strategy: 'assets.empty_version_strategy'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to use the empty version strategy, a better solution is to configure the version as empty rather than overwriting the strategy IMO. It avoids relying on the service id used in FrameworkBundle (se my comment in the symfony issue)


.. code-block:: xml

<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:assets version_strategy="app.asset.my_versioning_strategy">
<framework:package
name="foo_package"
version-strategy="assets.empty_version_strategy" />
</framework:assets>
</framework:config>
</container>

.. code-block:: php

// app/config/config.php
$container->loadFromExtension('framework', array(
'assets' => array(
'version_strategy' => 'app.asset.my_versioning_strategy',
'packages' => array(
'foo_package' => array(
// ...
'version_strategy' => 'assets.empty_version_strategy',
),
),
),
));

.. note::

Expand Down