Skip to content

Commit b2c4d31

Browse files
committed
minor #9548 New section about JSON file manifest strategy (jeremyjumeau, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #9548). Discussion ---------- New section about JSON file manifest strategy @see https://symfony.com/blog/new-in-symfony-3-3-manifest-based-asset-versioning <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- b8a67a4 Added a missing comma 3266473 Reword b33168a Link to the asset component documentation e0ed723 Fix typo 3ef51fc New section about JSON file manifest strategy
2 parents 2e820e6 + b8a67a4 commit b2c4d31

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

components/asset.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,33 @@ string as the second argument of the ``StaticVersionStrategy`` constructor::
139139
echo $package->getUrl('image.png');
140140
// result: v1/image.png
141141

142+
JSON File Manifest
143+
..................
144+
145+
A popular strategy to manage asset versioning, which is used by tools such as
146+
`Webpack`_, is to generate a JSON file mapping all source file names to their
147+
corresponding output file:
148+
149+
.. code-block:: json
150+
151+
// rev-manifest.json
152+
{
153+
"css/app.css": "build/css/app.b916426ea1d10021f3f17ce8031f93c2.css",
154+
"js/app.js": "build/js/app.13630905267b809161e71d0f8a0c017b.js",
155+
"...": "..."
156+
}
157+
158+
In those cases, use the
159+
:class:`Symfony\\Component\\Asset\\VersionStrategy\\JsonManifestVersionStrategy`::
160+
161+
use Symfony\Component\Asset\Package;
162+
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
163+
164+
$package = new Package(new JsonManifestVersionStrategy(__DIR__'./rev-manifest.json'));
165+
166+
echo $package->getUrl('css/app.css');
167+
// result: build/css/app.b916426ea1d10021f3f17ce8031f93c2.css
168+
142169
Custom Version Strategies
143170
.........................
144171

@@ -349,3 +376,4 @@ Learn more
349376
----------
350377

351378
.. _Packagist: https://packagist.org/packages/symfony/asset
379+
.. _`Webpack`: https://webpack.js.org/

frontend/encore/versioning.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ like normal:
5959
<script src="{{ asset('build/app.js') }}"></script>
6060
6161
<link href="{{ asset('build/dashboard.css') }}" rel="stylesheet" />
62+
63+
Learn more
64+
----------
65+
66+
* :doc:`/components/asset`

0 commit comments

Comments
 (0)