incenteev / hashed-asset-bundle
Apply an asset version based on a hash of the asset for symfony/asset
Installs: 448 296
Dependents: 1
Suggesters: 0
Security: 0
Stars: 23
Watchers: 4
Forks: 4
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.4
- symfony/asset: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
- symfony/cache: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
- symfony/config: ^4.4 || ^5.3 || ^6.0 || ^7.0
- symfony/dependency-injection: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
- symfony/finder: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
- symfony/framework-bundle: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
- symfony/http-kernel: ^4.4.13 || ^5.3 || ^6.0 || ^7.0
Requires (Dev)
- jangregor/phpstan-prophecy: ^1.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.5
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpstan/phpstan-symfony: ^1.1
- phpunit/phpunit: ^9.5
- symfony/phpunit-bridge: ^5.3 || ^6.0 || ^7.0
README
The HashedAssetBundle provides an asset version strategy which uses a hash of the file content as asset version. This allows bumping the asset version separately for each asset (automatically).
Installation
Use Composer to install the bundle:
$ composer require incenteev/hashed-asset-bundle
Usage
Register the bundle in the kernel:
// app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Incenteev\HashedAssetBundle\IncenteevHashedAssetBundle(), ); } }
Then configure FrameworkBundle to use the new version strategy:
framework: assets: version_strategy: incenteev_hashed_asset.strategy
Advanced configuration
The default configuration should fit common needs, but the bundle exposes a few configuration settings in case you need them:
incenteev_hashed_asset: # Absolute path to the folder in which assets can be found # Note: in case you apply a base_path in your asset package, it is not # yet applied to the string received by the bundle web_root: '%kernel.project_dir%/web' # Format used to apply the version. This is equivalent to the # `framework > assets > version_format` of the static version strategy # of FrameworkBundle. version_format: '%%s?%%s'
License
This bundle is under the MIT license.
Alternative projects
If you want to apply cache busting by renaming files in your asset pipeline
(for instance with the webpack-encore versioning feature), have a look at the
json_manifest
strategy available in Symfony itself.
Reporting an issue or a feature request
Issues and feature requests are tracked in the Github issue tracker.