From 4f530d8e52b69c215014ece39ebeeda973e16881 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Mon, 6 Jul 2015 05:16:26 +0800 Subject: [PATCH 01/12] Cookbook entry: Asset - Custom Version Strategy --- cookbook/asset/custom_version_strategy.rst | 254 +++++++++++++++++++++ cookbook/asset/index.rst | 7 + reference/configuration/framework.rst | 76 ++++++ reference/twig_reference.rst | 2 + 4 files changed, 339 insertions(+) create mode 100644 cookbook/asset/custom_version_strategy.rst create mode 100644 cookbook/asset/index.rst diff --git a/cookbook/asset/custom_version_strategy.rst b/cookbook/asset/custom_version_strategy.rst new file mode 100644 index 00000000000..4d42a2981d2 --- /dev/null +++ b/cookbook/asset/custom_version_strategy.rst @@ -0,0 +1,254 @@ +.. index:: + single: Asset; Custom Version Strategy + +How to Use a Custom Version Strategy for Assets +=============================================== + +.. versionadded:: 2.7 + The Asset component was introduced in Symfony 2.7. + +Symfony by default does not perform asset versioning. You can specify the +:ref:`version ` and +:ref:`version_format ` configuration +options to add a simple version to all assets (or a specific set of assets +grouped as a :ref:`package `): + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + assets: + version: "20150530" + version_format: "%%s?version=%%s" + + .. code-block:: xml + + + + + + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('framework', array( + 'assets' => array( + 'version' => '20150530', + 'version_format' => '%%s?version=%%s', + ), + )); + +However, if you require more control, you need to create a custom version +strategy. + +Default Package +--------------- + +The default package is used when you do not specify a package name in the +:ref:`asset ` Twig function. In order to +override the version strategy used by the default package, it is necessary +to add a compiler pass. + +This example shows how to integrate with `gulp-buster`_. + +.. note:: + + busters.json as referenced below is the output from gulp-buster which + maps each asset file to its hash. A small snippet of the file's format + (JSON object): + + .. code-block:: json + + { + "js/script.js": "f9c7afd05729f10f55b689f36bb20172", + "css/style.css": "91cd067f79a5839536b46c494c4272d8" + } + +Create Compiler Pass +~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: php + + // src/AppBundle/DependencyInjection/Compiler/OverrideAssetsDefaultPackagePass.php + namespace AppBundle\DependencyInjection\Compiler; + + use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + use Symfony\Component\DependencyInjection\ContainerBuilder; + use Symfony\Component\DependencyInjection\Reference; + + class OverrideAssetsDefaultPackagePass implements CompilerPassInterface + { + public function process(ContainerBuilder $container) + { + $definition = $container->getDefinition('assets._default_package'); + $definition->replaceArgument(1, new Reference('app.assets.buster_version_strategy')); + } + } + +The code above fetches the service definition of the default package, and replaces +its second argument (the version strategy). + +Register Compiler Pass +~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: php + + // src/AppBundle/AppBundle.php + namespace AppBundle; + + use AppBundle\DependencyInjection\Compiler\OverrideAssetsDefaultPackagePass; + use Symfony\Component\DependencyInjection\ContainerBuilder; + use Symfony\Component\HttpKernel\Bundle\Bundle; + + class AppBundle extends Bundle + { + public function build(ContainerBuilder $container) + { + parent::build($container); + + // only register in prod environment + if ('prod' === $container->getParameter('kernel.environment')) { + $container->addCompilerPass(new OverrideAssetsDefaultPackagePass()); + } + } + } + +See :doc:`/cookbook/service_container/compiler_passes` for more information +on how to use compiler passes. + +Register Services +~~~~~~~~~~~~~~~~~ + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/services.yml + services: + app.assets.buster_version_strategy: + class: AppBundle\Asset\VersionStrategy\BusterVersionStrategy + arguments: + - "%kernel.root_dir%/../busters.json" + - "%%s?version=%%s" + public: false + + .. code-block:: xml + + + + + + + %kernel.root_dir%/../busters.json + %%s?version=%%s + + + + + .. code-block:: php + + // app/config/services.php + use Symfony\Component\DependencyInjection\Definition; + + $definition = new Definition( + 'AppBundle\Asset\VersionStrategy\BusterVersionStrategy', + array( + '%kernel.root_dir%/../busters.json', + '%%s?version=%%s', + ) + ); + $definition->setPublic(false); + + $container->setDefinition('app.assets.buster_version_strategy', $definition); + +Implement VersionStrategyInterface +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: php + + // src/AppBundle/Asset/VersionStrategy/BusterVersionStrategy.php + namespace AppBundle\Asset\VersionStrategy; + + use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface; + + class BusterVersionStrategy implements VersionStrategyInterface + { + /** + * @var string + */ + private $manifestPath; + + /** + * @var string + */ + private $format; + + /** + * @var string[] + */ + private $hashes; + + /** + * @param string $manifestPath + * @param string|null $format + */ + public function __construct($manifestPath, $format = null) + { + $this->manifestPath = $manifestPath; + $this->format = $format ?: '%s?%s'; + } + + public function getVersion($path) + { + if (!is_array($this->hashes)) { + $this->hashes = $this->loadManifest(); + } + + return isset($this->hashes[$path]) ? $this->hashes[$path] : ''; + } + + public function applyVersion($path) + { + $version = $this->getVersion($path); + + if ('' === $version) { + return $path; + } + + $versionized = sprintf($this->format, ltrim($path, '/'), $version); + + if ($path && '/' === $path[0]) { + return '/'.$versionized; + } + + return $versionized; + } + + private function loadManifest(array $options) + { + $hashes = json_decode(file_get_contents($this->manifestPath), true); + + return $hashes; + } + } + +.. _`gulp-buster`: https://www.npmjs.com/package/gulp-buster diff --git a/cookbook/asset/index.rst b/cookbook/asset/index.rst new file mode 100644 index 00000000000..72838e118cd --- /dev/null +++ b/cookbook/asset/index.rst @@ -0,0 +1,7 @@ +Asset +===== + +.. toctree:: + :maxdepth: 2 + + custom_version_strategy diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 8e6dcdde3b9..242b9b7c638 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1090,6 +1090,7 @@ option. ``version``. This makes it easier to increment the cache on each deployment. +.. _reference-framework-assets-version-format: .. _reference-templating-version-format: .. _reference-assets-version-format: @@ -1255,6 +1256,81 @@ templating loaders. Templating loaders are used to find and load templates from a resource (e.g. a filesystem or database). Templating loaders must implement :class:`Symfony\\Component\\Templating\\Loader\\LoaderInterface`. +.. _reference-framework-assets-packages: + +packages +........ + +You can group assets into packages, to specify different base URLs for them: + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + framework: + # ... + templating: + packages: + avatars: + base_urls: 'http://static_cdn.example.com/avatars' + + .. code-block:: xml + + + + + + + + + + + + + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('framework', array( + // ... + 'templating' => array( + 'packages' => array( + 'avatars' => array( + 'base_urls' => 'http://static_cdn.example.com/avatars', + ), + ), + ), + )); + +Now you can use the ``avatars`` package in your templates: + +.. configuration-block:: php + + .. code-block:: html+jinja + + + + .. code-block:: html+php + + + +Each package can configure the following options: + +* :ref:`base_urls ` +* :ref:`version ` +* :ref:`version_format ` + +>>>>>>> Cookbook entry: Asset - Custom Version Strategy translator ~~~~~~~~~~ diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 33094672e2e..6a6c7a71ae7 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -93,6 +93,8 @@ Returns an instance of ``ControllerReference`` to be used with functions like :ref:`render() ` and :ref:`render_esi() `. +.. _reference-twig-function-asset: + asset ~~~~~ From 80d0ca2f4ba4730228aec6f44db13149a4dccd51 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 10:04:48 +0100 Subject: [PATCH 02/12] Simplified the intro --- cookbook/asset/custom_version_strategy.rst | 55 ++++------------------ 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/cookbook/asset/custom_version_strategy.rst b/cookbook/asset/custom_version_strategy.rst index 4d42a2981d2..80642ca992c 100644 --- a/cookbook/asset/custom_version_strategy.rst +++ b/cookbook/asset/custom_version_strategy.rst @@ -7,54 +7,17 @@ How to Use a Custom Version Strategy for Assets .. versionadded:: 2.7 The Asset component was introduced in Symfony 2.7. -Symfony by default does not perform asset versioning. You can specify the +Asset versioning is a technique that improves the performance of web +applications by adding a version identifier to the URL of your static assets +(CSS, JavaScript, images, etc.) When the content of the asset changes, the +identifier changes and the browser is forced to download it again instead of +using the cached version. + +Symfony supports the basic asset versioning thanks to the :ref:`version ` and :ref:`version_format ` configuration -options to add a simple version to all assets (or a specific set of assets -grouped as a :ref:`package `): - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - framework: - assets: - version: "20150530" - version_format: "%%s?version=%%s" - - .. code-block:: xml - - - - - - - - - - .. code-block:: php - - // app/config/config.php - $container->loadFromExtension('framework', array( - 'assets' => array( - 'version' => '20150530', - 'version_format' => '%%s?version=%%s', - ), - )); - -However, if you require more control, you need to create a custom version -strategy. +options. If your application requires a more advanced versioning, you can create +your own version strategy. Default Package --------------- From 40dff640cf1825db7948bd2425466978cc32ac71 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 10:33:26 +0100 Subject: [PATCH 03/12] Minor updates to the doc and service config --- cookbook/asset/custom_version_strategy.rst | 223 ++++++++++----------- 1 file changed, 104 insertions(+), 119 deletions(-) diff --git a/cookbook/asset/custom_version_strategy.rst b/cookbook/asset/custom_version_strategy.rst index 80642ca992c..a8cd7eb9bab 100644 --- a/cookbook/asset/custom_version_strategy.rst +++ b/cookbook/asset/custom_version_strategy.rst @@ -19,83 +19,99 @@ Symfony supports the basic asset versioning thanks to the options. If your application requires a more advanced versioning, you can create your own version strategy. -Default Package ---------------- +Creating your Own Asset Version Strategy +---------------------------------------- -The default package is used when you do not specify a package name in the -:ref:`asset ` Twig function. In order to -override the version strategy used by the default package, it is necessary -to add a compiler pass. +The following example shows how to create a version strategy compatible with +`gulp-buster`_. This tool defines a configuration file called ``busters.json`` +which maps each asset file to its content hash: -This example shows how to integrate with `gulp-buster`_. +.. code-block:: json -.. note:: + { + "js/script.js": "f9c7afd05729f10f55b689f36bb20172", + "css/style.css": "91cd067f79a5839536b46c494c4272d8" + } - busters.json as referenced below is the output from gulp-buster which - maps each asset file to its hash. A small snippet of the file's format - (JSON object): +Implement VersionStrategyInterface +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - .. code-block:: json +Asset version strategies are PHP classes that implement the +:class:`Symfony\\Component\\Asset\\VersionStrategy\\VersionStrategyInterface`. +In this example, the constructor of the class takes as arguments the path to +the manifest file generated by gulp-buster and the format of the generated +version string:: - { - "js/script.js": "f9c7afd05729f10f55b689f36bb20172", - "css/style.css": "91cd067f79a5839536b46c494c4272d8" - } + // src/AppBundle/Asset/VersionStrategy/GulpBusterVersionStrategy.php + namespace AppBundle\Asset\VersionStrategy; -Create Compiler Pass -~~~~~~~~~~~~~~~~~~~~ + use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface; -.. code-block:: php + class GulpBusterVersionStrategy implements VersionStrategyInterface + { + /** + * @var string + */ + private $manifestPath; - // src/AppBundle/DependencyInjection/Compiler/OverrideAssetsDefaultPackagePass.php - namespace AppBundle\DependencyInjection\Compiler; + /** + * @var string + */ + private $format; - use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; - use Symfony\Component\DependencyInjection\ContainerBuilder; - use Symfony\Component\DependencyInjection\Reference; + /** + * @var string[] + */ + private $hashes; - class OverrideAssetsDefaultPackagePass implements CompilerPassInterface - { - public function process(ContainerBuilder $container) + /** + * @param string $manifestPath + * @param string|null $format + */ + public function __construct($manifestPath, $format = null) { - $definition = $container->getDefinition('assets._default_package'); - $definition->replaceArgument(1, new Reference('app.assets.buster_version_strategy')); + $this->manifestPath = $manifestPath; + $this->format = $format ?: '%s?%s'; } - } -The code above fetches the service definition of the default package, and replaces -its second argument (the version strategy). + public function getVersion($path) + { + if (!is_array($this->hashes)) { + $this->hashes = $this->loadManifest(); + } + + return isset($this->hashes[$path]) ? $this->hashes[$path] : ''; + } -Register Compiler Pass -~~~~~~~~~~~~~~~~~~~~~~ + public function applyVersion($path) + { + $version = $this->getVersion($path); -.. code-block:: php + if ('' === $version) { + return $path; + } - // src/AppBundle/AppBundle.php - namespace AppBundle; + $versionized = sprintf($this->format, ltrim($path, '/'), $version); - use AppBundle\DependencyInjection\Compiler\OverrideAssetsDefaultPackagePass; - use Symfony\Component\DependencyInjection\ContainerBuilder; - use Symfony\Component\HttpKernel\Bundle\Bundle; + if ($path && '/' === $path[0]) { + return '/'.$versionized; + } - class AppBundle extends Bundle - { - public function build(ContainerBuilder $container) + return $versionized; + } + + private function loadManifest(array $options) { - parent::build($container); + $hashes = json_decode(file_get_contents($this->manifestPath), true); - // only register in prod environment - if ('prod' === $container->getParameter('kernel.environment')) { - $container->addCompilerPass(new OverrideAssetsDefaultPackagePass()); - } + return $hashes; } } -See :doc:`/cookbook/service_container/compiler_passes` for more information -on how to use compiler passes. +Register the Strategy Service +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Register Services -~~~~~~~~~~~~~~~~~ +After creating the strategy PHP class, register it as a Symfony service .. configuration-block:: @@ -103,8 +119,8 @@ Register Services # app/config/services.yml services: - app.assets.buster_version_strategy: - class: AppBundle\Asset\VersionStrategy\BusterVersionStrategy + app.assets.versioning.gulp_buster: + class: AppBundle\Asset\VersionStrategy\GulpBusterVersionStrategy arguments: - "%kernel.root_dir%/../busters.json" - "%%s?version=%%s" @@ -120,7 +136,8 @@ Register Services http://symfony.com/schema/dic/services/services-1.0.xsd" > - + %kernel.root_dir%/../busters.json %%s?version=%%s @@ -133,7 +150,7 @@ Register Services use Symfony\Component\DependencyInjection\Definition; $definition = new Definition( - 'AppBundle\Asset\VersionStrategy\BusterVersionStrategy', + 'AppBundle\Asset\VersionStrategy\GulpBusterVersionStrategy', array( '%kernel.root_dir%/../busters.json', '%%s?version=%%s', @@ -141,77 +158,45 @@ Register Services ); $definition->setPublic(false); - $container->setDefinition('app.assets.buster_version_strategy', $definition); - -Implement VersionStrategyInterface -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + $container->setDefinition('app.assets.versioning.gulp_buster', $definition); -.. code-block:: php +Finally, enable the new asset versioning for all the application assets or just +for some :ref:`asset package ` thanks to +the :ref:`version_strategy ` option: - // src/AppBundle/Asset/VersionStrategy/BusterVersionStrategy.php - namespace AppBundle\Asset\VersionStrategy; - - use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface; - - class BusterVersionStrategy implements VersionStrategyInterface - { - /** - * @var string - */ - private $manifestPath; - - /** - * @var string - */ - private $format; - - /** - * @var string[] - */ - private $hashes; - - /** - * @param string $manifestPath - * @param string|null $format - */ - public function __construct($manifestPath, $format = null) - { - $this->manifestPath = $manifestPath; - $this->format = $format ?: '%s?%s'; - } - - public function getVersion($path) - { - if (!is_array($this->hashes)) { - $this->hashes = $this->loadManifest(); - } - - return isset($this->hashes[$path]) ? $this->hashes[$path] : ''; - } +.. configuration-block:: - public function applyVersion($path) - { - $version = $this->getVersion($path); + .. code-block:: yaml - if ('' === $version) { - return $path; - } + # app/config/config.yml + framework: + # ... + assets: + version_strategy: 'app.assets.versioning.gulp_buster' - $versionized = sprintf($this->format, ltrim($path, '/'), $version); + .. code-block:: xml - if ($path && '/' === $path[0]) { - return '/'.$versionized; - } + + + - return $versionized; - } + + + + - private function loadManifest(array $options) - { - $hashes = json_decode(file_get_contents($this->manifestPath), true); + .. code-block:: php - return $hashes; - } - } + // app/config/config.php + $container->loadFromExtension('framework', array( + // ... + 'assets' => array( + 'version_strategy' => 'app.assets.versioning.gulp_buster', + ), + )); .. _`gulp-buster`: https://www.npmjs.com/package/gulp-buster From 5971ce0626425daebdf710a915453911b22e4f19 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 10:38:02 +0100 Subject: [PATCH 04/12] Removed an unneeded file --- cookbook/asset/index.rst | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 cookbook/asset/index.rst diff --git a/cookbook/asset/index.rst b/cookbook/asset/index.rst deleted file mode 100644 index 72838e118cd..00000000000 --- a/cookbook/asset/index.rst +++ /dev/null @@ -1,7 +0,0 @@ -Asset -===== - -.. toctree:: - :maxdepth: 2 - - custom_version_strategy From c59cff6ea8e1839e5be564a8e332ed39839156be Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 10:40:48 +0100 Subject: [PATCH 05/12] Moved the article to its new location --- {cookbook/asset => frontend}/custom_version_strategy.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {cookbook/asset => frontend}/custom_version_strategy.rst (100%) diff --git a/cookbook/asset/custom_version_strategy.rst b/frontend/custom_version_strategy.rst similarity index 100% rename from cookbook/asset/custom_version_strategy.rst rename to frontend/custom_version_strategy.rst From ab8fa54c5e0518e1ab82c543a0a378247c245fd7 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 10:50:06 +0100 Subject: [PATCH 06/12] Fixed a rebase error --- reference/configuration/framework.rst | 75 --------------------------- 1 file changed, 75 deletions(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 242b9b7c638..7d3d7c8bcbc 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1256,81 +1256,6 @@ templating loaders. Templating loaders are used to find and load templates from a resource (e.g. a filesystem or database). Templating loaders must implement :class:`Symfony\\Component\\Templating\\Loader\\LoaderInterface`. -.. _reference-framework-assets-packages: - -packages -........ - -You can group assets into packages, to specify different base URLs for them: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - framework: - # ... - templating: - packages: - avatars: - base_urls: 'http://static_cdn.example.com/avatars' - - .. code-block:: xml - - - - - - - - - - - - - - - - - .. code-block:: php - - // app/config/config.php - $container->loadFromExtension('framework', array( - // ... - 'templating' => array( - 'packages' => array( - 'avatars' => array( - 'base_urls' => 'http://static_cdn.example.com/avatars', - ), - ), - ), - )); - -Now you can use the ``avatars`` package in your templates: - -.. configuration-block:: php - - .. code-block:: html+jinja - - - - .. code-block:: html+php - - - -Each package can configure the following options: - -* :ref:`base_urls ` -* :ref:`version ` -* :ref:`version_format ` - ->>>>>>> Cookbook entry: Asset - Custom Version Strategy translator ~~~~~~~~~~ From f038483ec4273573a43d5dfc8a009c10bed791f4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 11:31:03 +0100 Subject: [PATCH 07/12] Removed an unneeded change --- reference/twig_reference.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 6a6c7a71ae7..33094672e2e 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -93,8 +93,6 @@ Returns an instance of ``ControllerReference`` to be used with functions like :ref:`render() ` and :ref:`render_esi() `. -.. _reference-twig-function-asset: - asset ~~~~~ From 482fda5659c59bce933eb9462e0bbf0221cd0887 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 15 Nov 2016 11:56:21 +0100 Subject: [PATCH 08/12] Minor rewords and fixes --- frontend/custom_version_strategy.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst index a8cd7eb9bab..d942b459526 100644 --- a/frontend/custom_version_strategy.rst +++ b/frontend/custom_version_strategy.rst @@ -8,16 +8,17 @@ How to Use a Custom Version Strategy for Assets The Asset component was introduced in Symfony 2.7. Asset versioning is a technique that improves the performance of web -applications by adding a version identifier to the URL of your static assets -(CSS, JavaScript, images, etc.) When the content of the asset changes, the -identifier changes and the browser is forced to download it again instead of -using the cached version. +applications by adding a version identifier to the URL of the static assets +(CSS, JavaScript, images, etc.) When the content of the asset changes, its +identifier is also modified to force the browser download it again instead of +reusing the cached asset. -Symfony supports the basic asset versioning thanks to the +Symfony supports asset versioning thanks to the :ref:`version ` and :ref:`version_format ` configuration -options. If your application requires a more advanced versioning, you can create -your own version strategy. +options. If your application requires a more advanced versioning, such as +generating the version dynamically based on some external information, you can +create your own version strategy. Creating your Own Asset Version Strategy ---------------------------------------- @@ -39,7 +40,7 @@ Implement VersionStrategyInterface Asset version strategies are PHP classes that implement the :class:`Symfony\\Component\\Asset\\VersionStrategy\\VersionStrategyInterface`. In this example, the constructor of the class takes as arguments the path to -the manifest file generated by gulp-buster and the format of the generated +the manifest file generated by `gulp-buster`_ and the format of the generated version string:: // src/AppBundle/Asset/VersionStrategy/GulpBusterVersionStrategy.php From 2830ba0d55bd3d9c03b1b0ff75ffdf5155681be1 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 21 Nov 2016 09:48:09 +0100 Subject: [PATCH 09/12] Added the missing doc label --- reference/configuration/framework.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 7d3d7c8bcbc..ce271b6e94f 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -945,6 +945,8 @@ collection each time it generates an asset's path: ), )); +.. _reference-framework-assets-packages: + packages ........ From a02f3b35371454daf599fe7edc6b9099f4e055f5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 8 Dec 2016 22:31:12 +0100 Subject: [PATCH 10/12] Added the version_strategy option to the config reference --- reference/configuration/framework.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index ce271b6e94f..bd658d34563 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -75,6 +75,7 @@ Configuration * `packages`_ * `version`_ * `version_format`_ + * `version_strategy`_ * `templating`_ * `hinclude_default_template`_ * :ref:`form ` @@ -1015,6 +1016,7 @@ Each package can configure the following options: * :ref:`base_urls ` * :ref:`version ` * :ref:`version_format ` +* :ref:`version_strategy ` .. _reference-framework-assets-version: .. _ref-framework-assets-version: @@ -1133,6 +1135,16 @@ is set to ``5``, the asset's path would be ``/images/logo.png?version=5``. any URL rewriting. The latter option is useful if you would like older asset versions to remain accessible at their original URL. +.. _reference-framework-assets-version_strategy: + +version_strategy +................ + +**type**: ``string`` **default**: null + +The service id of the :doc:`asset version strategy ` +applied to the assets. + templating ~~~~~~~~~~ From 981e82d6df14ec79ade24d18e8e44e4ccf5894e4 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 9 Dec 2016 08:41:39 +0100 Subject: [PATCH 11/12] Misc fixes --- frontend/custom_version_strategy.rst | 10 ++++------ reference/configuration/framework.rst | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/frontend/custom_version_strategy.rst b/frontend/custom_version_strategy.rst index d942b459526..deaa99031c4 100644 --- a/frontend/custom_version_strategy.rst +++ b/frontend/custom_version_strategy.rst @@ -10,7 +10,7 @@ How to Use a Custom Version Strategy for Assets Asset versioning is a technique that improves the performance of web applications by adding a version identifier to the URL of the static assets (CSS, JavaScript, images, etc.) When the content of the asset changes, its -identifier is also modified to force the browser download it again instead of +identifier is also modified to force the browser to download it again instead of reusing the cached asset. Symfony supports asset versioning thanks to the @@ -103,16 +103,14 @@ version string:: private function loadManifest(array $options) { - $hashes = json_decode(file_get_contents($this->manifestPath), true); - - return $hashes; + return json_decode(file_get_contents($this->manifestPath), true); } } Register the Strategy Service ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After creating the strategy PHP class, register it as a Symfony service +After creating the strategy PHP class, register it as a Symfony service. .. configuration-block:: @@ -186,7 +184,7 @@ the :ref:`version_strategy ` option http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index bd658d34563..2a139dd19a5 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1142,7 +1142,7 @@ version_strategy **type**: ``string`` **default**: null -The service id of the :doc:`asset version strategy ` +The service id of the :doc:`asset version strategy ` applied to the assets. templating From 13999679b2926360927bb9a1ea54ac46590295cd Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 9 Dec 2016 08:50:25 +0100 Subject: [PATCH 12/12] Fixed a label name --- reference/configuration/framework.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/configuration/framework.rst b/reference/configuration/framework.rst index 2a139dd19a5..72a46d16034 100644 --- a/reference/configuration/framework.rst +++ b/reference/configuration/framework.rst @@ -1016,7 +1016,7 @@ Each package can configure the following options: * :ref:`base_urls ` * :ref:`version ` * :ref:`version_format ` -* :ref:`version_strategy ` +* :ref:`version_strategy ` .. _reference-framework-assets-version: .. _ref-framework-assets-version: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy