vinorcola / distant-versioned-assets-bundle
Use distant versioned assets by loading the manifest.json file.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
- psr/cache: ^1.0
- symfony/config: ^4.0
- symfony/dependency-injection: ^4.0
- symfony/http-kernel: ^4.0
- twig/twig: ^2.0
This package is auto-updated.
Last update: 2025-04-07 16:49:52 UTC
README
Link versioned assets across projects.
If you application needs to use some assets from a distant source and those assets are versioned, you can use this bundle to link them. The only requirement is that the distant source publish a manifest.json
.
You can configure several targets (i.e. distant sources)
Installation
composer require vinorcola/distant-versioned-assets-bundle
Configuration
You must configure at least one target.
# config/packages/vinorcola_distant_versioned_assets.yaml vinorcola_distant_versioned_assets: targets: default: url: https://my-distant-storage.com manifestPath: build/manifest.json # Optional, default value cacheTtl: 3600 # Optional, default value
The manifest path is optional and is build/manifest.json
by default. The manifest file is fetch and its content is cached to avoid querying the distant source at each request. You can configure the cache TTL (1 hour by default).
Usage
Then, in Twig template, you can simply use the distantAsset
function instead of asset
function.
<link href="{{ distantAsset('build/style.css) }}" rel="stylesheet" /> <script src="{{ distantAsset('build/library.js') }}"></script>
Advanced usage
You can configure several targets if needed.
# config/packages/vinorcola_distant_versioned_assets.yaml vinorcola_distant_versioned_assets: targets: default: url: https://my-distant-storage.com reference: url: https://my-reference-storage.com
<script src="{{ distantAsset('build/library.js') }}"></script> {# Uses the default target. #} <script src="{{ distantAsset('build/library.js', 'reference) }}"></script> {# Uses the reference target. #}
If you have no target named default
, you must indicate the default target:
# config/packages/vinorcola_distant_versioned_assets.yaml vinorcola_distant_versioned_assets: defaultTarget: storage targets: storage: url: https://my-distant-storage.com reference: url: https://my-reference-storage.com
Note that if you only have one target, there is no need to configure the defaultTarget
option, whatever the target name is.