Skip to content

Commit cc12d7f

Browse files
author
Henry Snoek
committed
change order of assets configuration options
1 parent 61403e7 commit cc12d7f

File tree

1 file changed

+120
-120
lines changed

1 file changed

+120
-120
lines changed

reference/configuration/framework.rst

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ Configuration
7070
* `gc_maxlifetime`_
7171
* `save_path`_
7272
* `assets`_
73-
* `version`_
74-
* `version_format`_
7573
* `base_urls`_
7674
* `packages`_
75+
* `version`_
76+
* `version_format`_
7777
* `templating`_
7878
* `hinclude_default_template`_
7979
* :ref:`form <reference-templating-form>`
@@ -852,124 +852,6 @@ setting the value to ``null``:
852852
assets
853853
~~~~~~
854854

855-
.. _reference-framework-assets-version:
856-
.. _ref-framework-assets-version:
857-
858-
version
859-
.......
860-
861-
**type**: ``string``
862-
863-
This option is used to *bust* the cache on assets by globally adding a query
864-
parameter to all rendered asset paths (e.g. ``/images/logo.png?v2``). This
865-
applies only to assets rendered via the Twig ``asset`` function (or PHP
866-
equivalent) as well as assets rendered with Assetic.
867-
868-
For example, suppose you have the following:
869-
870-
.. configuration-block::
871-
872-
.. code-block:: html+twig
873-
874-
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
875-
876-
.. code-block:: php
877-
878-
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
879-
880-
By default, this will render a path to your image such as ``/images/logo.png``.
881-
Now, activate the ``version`` option:
882-
883-
.. configuration-block::
884-
885-
.. code-block:: yaml
886-
887-
# app/config/config.yml
888-
framework:
889-
# ...
890-
assets:
891-
version: 'v2'
892-
893-
.. code-block:: xml
894-
895-
<!-- app/config/config.xml -->
896-
<?xml version="1.0" encoding="UTF-8" ?>
897-
<container xmlns="http://symfony.com/schema/dic/services"
898-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
899-
xmlns:framework="http://symfony.com/schema/dic/symfony"
900-
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
901-
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
902-
903-
<framework:assets version="v2">
904-
</container>
905-
906-
.. code-block:: php
907-
908-
// app/config/config.php
909-
$container->loadFromExtension('framework', array(
910-
// ...
911-
'assets' => array(
912-
'version' => 'v2',
913-
),
914-
));
915-
916-
Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
917-
this feature, you **must** manually increment the ``version`` value
918-
before each deployment so that the query parameters change.
919-
920-
It's also possible to set the version value on an asset-by-asset basis (instead
921-
of using the global version - e.g. ``v2`` - set here). See
922-
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
923-
924-
You can also control how the query string works via the `version_format`_
925-
option.
926-
927-
.. tip::
928-
929-
As with all settings, you can use a parameter as value for the
930-
``version``. This makes it easier to increment the cache on each
931-
deployment.
932-
933-
.. _reference-templating-version-format:
934-
.. _reference-assets-version-format:
935-
936-
version_format
937-
..............
938-
939-
**type**: ``string`` **default**: ``%%s?%%s``
940-
941-
This specifies a :phpfunction:`sprintf` pattern that will be used with the
942-
`version`_ option to construct an asset's path. By default, the pattern
943-
adds the asset's version as a query string. For example, if
944-
``version_format`` is set to ``%%s?version=%%s`` and ``version``
945-
is set to ``5``, the asset's path would be ``/images/logo.png?version=5``.
946-
947-
.. note::
948-
949-
All percentage signs (``%``) in the format string must be doubled to
950-
escape the character. Without escaping, values might inadvertently be
951-
interpreted as :ref:`book-service-container-parameters`.
952-
953-
.. tip::
954-
955-
Some CDN's do not support cache-busting via query strings, so injecting
956-
the version into the actual file path is necessary. Thankfully,
957-
``version_format`` is not limited to producing versioned query
958-
strings.
959-
960-
The pattern receives the asset's original path and version as its first
961-
and second parameters, respectively. Since the asset's path is one
962-
parameter, you cannot modify it in-place (e.g. ``/images/logo-v5.png``);
963-
however, you can prefix the asset's path using a pattern of
964-
``version-%%2$s/%%1$s``, which would result in the path
965-
``version-5/images/logo.png``.
966-
967-
URL rewrite rules could then be used to disregard the version prefix
968-
before serving the asset. Alternatively, you could copy assets to the
969-
appropriate version path as part of your deployment process and forgot
970-
any URL rewriting. The latter option is useful if you would like older
971-
asset versions to remain accessible at their original URL.
972-
973855
.. _reference-templating-base-urls:
974856
.. _reference-assets-base-urls:
975857

@@ -1089,6 +971,124 @@ Each package can configure the following options:
1089971
* :ref:`version <reference-framework-assets-version>`
1090972
* :ref:`version_format <reference-assets-version-format>`
1091973

974+
.. _reference-framework-assets-version:
975+
.. _ref-framework-assets-version:
976+
977+
version
978+
.......
979+
980+
**type**: ``string``
981+
982+
This option is used to *bust* the cache on assets by globally adding a query
983+
parameter to all rendered asset paths (e.g. ``/images/logo.png?v2``). This
984+
applies only to assets rendered via the Twig ``asset`` function (or PHP
985+
equivalent) as well as assets rendered with Assetic.
986+
987+
For example, suppose you have the following:
988+
989+
.. configuration-block::
990+
991+
.. code-block:: html+twig
992+
993+
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
994+
995+
.. code-block:: php
996+
997+
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
998+
999+
By default, this will render a path to your image such as ``/images/logo.png``.
1000+
Now, activate the ``version`` option:
1001+
1002+
.. configuration-block::
1003+
1004+
.. code-block:: yaml
1005+
1006+
# app/config/config.yml
1007+
framework:
1008+
# ...
1009+
assets:
1010+
version: 'v2'
1011+
1012+
.. code-block:: xml
1013+
1014+
<!-- app/config/config.xml -->
1015+
<?xml version="1.0" encoding="UTF-8" ?>
1016+
<container xmlns="http://symfony.com/schema/dic/services"
1017+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1018+
xmlns:framework="http://symfony.com/schema/dic/symfony"
1019+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
1020+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
1021+
1022+
<framework:assets version="v2">
1023+
</container>
1024+
1025+
.. code-block:: php
1026+
1027+
// app/config/config.php
1028+
$container->loadFromExtension('framework', array(
1029+
// ...
1030+
'assets' => array(
1031+
'version' => 'v2',
1032+
),
1033+
));
1034+
1035+
Now, the same asset will be rendered as ``/images/logo.png?v2`` If you use
1036+
this feature, you **must** manually increment the ``version`` value
1037+
before each deployment so that the query parameters change.
1038+
1039+
It's also possible to set the version value on an asset-by-asset basis (instead
1040+
of using the global version - e.g. ``v2`` - set here). See
1041+
:ref:`Versioning by Asset <book-templating-version-by-asset>` for details.
1042+
1043+
You can also control how the query string works via the `version_format`_
1044+
option.
1045+
1046+
.. tip::
1047+
1048+
As with all settings, you can use a parameter as value for the
1049+
``version``. This makes it easier to increment the cache on each
1050+
deployment.
1051+
1052+
.. _reference-templating-version-format:
1053+
.. _reference-assets-version-format:
1054+
1055+
version_format
1056+
..............
1057+
1058+
**type**: ``string`` **default**: ``%%s?%%s``
1059+
1060+
This specifies a :phpfunction:`sprintf` pattern that will be used with the
1061+
`version`_ option to construct an asset's path. By default, the pattern
1062+
adds the asset's version as a query string. For example, if
1063+
``version_format`` is set to ``%%s?version=%%s`` and ``version``
1064+
is set to ``5``, the asset's path would be ``/images/logo.png?version=5``.
1065+
1066+
.. note::
1067+
1068+
All percentage signs (``%``) in the format string must be doubled to
1069+
escape the character. Without escaping, values might inadvertently be
1070+
interpreted as :ref:`book-service-container-parameters`.
1071+
1072+
.. tip::
1073+
1074+
Some CDN's do not support cache-busting via query strings, so injecting
1075+
the version into the actual file path is necessary. Thankfully,
1076+
``version_format`` is not limited to producing versioned query
1077+
strings.
1078+
1079+
The pattern receives the asset's original path and version as its first
1080+
and second parameters, respectively. Since the asset's path is one
1081+
parameter, you cannot modify it in-place (e.g. ``/images/logo-v5.png``);
1082+
however, you can prefix the asset's path using a pattern of
1083+
``version-%%2$s/%%1$s``, which would result in the path
1084+
``version-5/images/logo.png``.
1085+
1086+
URL rewrite rules could then be used to disregard the version prefix
1087+
before serving the asset. Alternatively, you could copy assets to the
1088+
appropriate version path as part of your deployment process and forgot
1089+
any URL rewriting. The latter option is useful if you would like older
1090+
asset versions to remain accessible at their original URL.
1091+
10921092
templating
10931093
~~~~~~~~~~
10941094

0 commit comments

Comments
 (0)