-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added "How to Use a Custom Version Strategy for Assets" #7141
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
Conversation
you should also fix conflicts |
6bc5efb
to
c59cff6
Compare
:ref:`version <reference-framework-assets-version>` and | ||
:ref:`version_format <reference-framework-assets-version-format>` configuration | ||
options. If your application requires a more advanced versioning, you can create | ||
your own version strategy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we add an example here, what "requires a more advanced versioning" means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworded this part a bit. Thanks.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gulp buster should be a link here, too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -93,6 +93,8 @@ Returns an instance of ``ControllerReference`` to be used with functions | ||
like :ref:`render() <reference-twig-function-render>` and | ||
:ref:`render_esi() <reference-twig-function-render-esi>`. | ||
|
||
.. _reference-twig-function-asset: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you add this here @javiereguiluz ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. It was in the original PR. I've just removed it.
|
||
Finally, enable the new asset versioning for all the application assets or just | ||
for some :ref:`asset package <reference-framework-assets-packages>` thanks to | ||
the :ref:`version_strategy <reference-framework-assets-version_strategy>` option: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have to add a label for this.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...] the browser to download it [...]
|
||
private function loadManifest(array $options) | ||
{ | ||
$hashes = json_decode(file_get_contents($this->manifestPath), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable is not needed.
Register the Strategy Service | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
After creating the strategy PHP class, register it as a Symfony service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing colon at the end of the sentence.
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:assets version_strategy="app.assets.versioning.gulp_buster" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In XML, the attribute should be version-strategy
.
|
||
**type**: ``string`` **default**: null | ||
|
||
The service id of the :doc:`asset version strategy </frontend/custom_version:strategy>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The colon in the path would be an underscore.
@xabbuh thanks for your review. I've fixed everything. |
@@ -1013,6 +1016,7 @@ Each package can configure the following options: | ||
* :ref:`base_urls <reference-assets-base-urls>` | ||
* :ref:`version <reference-framework-assets-version>` | ||
* :ref:`version_format <reference-assets-version-format>` | ||
* :ref:`version_strategy <reference-assets-version-strategy>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be reference-framework-assets-version_strategy
instead (see the build failure on Travis CI).
👍 Status: Reviewed |
Thank you Javier. |
…teohhanhui, javiereguiluz) This PR was merged into the 2.7 branch. Discussion ---------- Added "How to Use a Custom Version Strategy for Assets" This PR finishes the great work made by @teohhanhui in #5489. Commits ------- 1399967 Fixed a label name 981e82d Misc fixes a02f3b3 Added the version_strategy option to the config reference 2830ba0 Added the missing doc label 482fda5 Minor rewords and fixes f038483 Removed an unneeded change ab8fa54 Fixed a rebase error c59cff6 Moved the article to its new location 5971ce0 Removed an unneeded file 40dff64 Minor updates to the doc and service config 80d0ca2 Simplified the intro 4f530d8 Cookbook entry: Asset - Custom Version Strategy
And thank you for starting this awesome PR @teohhanhui! |
This PR was merged into the 2.7 branch. Discussion ---------- Revert the merge of #7141 I shouldn't have merged #7141 into the `2.7` branch as the related code PR (symfony/symfony#17532) was released with Symfony 3.1. Commits ------- 0f7c7d5 Revert "minor #7141 Added "How to Use a Custom Version Strategy for Assets" (teohhanhui, javiereguiluz)"
* 2.7: Revert "minor #7141 Added "How to Use a Custom Version Strategy for Assets" (teohhanhui, javiereguiluz)"
* 2.8: Revert "minor #7141 Added "How to Use a Custom Version Strategy for Assets" (teohhanhui, javiereguiluz)"
* 3.1: Revert "minor #7141 Added "How to Use a Custom Version Strategy for Assets" (teohhanhui, javiereguiluz)"
This PR finishes the great work made by @teohhanhui in #5489.