Download the PHP package becklyn/assets-bundle without Composer
On this page you can find all versions of the php package becklyn/assets-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package assets-bundle
BecklynAssetsBundle
High-performance asset handling for symfony projects.
This bundle is a simplified and specialized replacement for symfony/asset
.
Installation
and then add the bundle in your AppKernel
/ bundles.php
.
Load the routes (preferably only in dev
):
To use the static compression of assets, install zopfli
or gzip
.
Info / Purpose
This bundle aims to provide a way to transparently handle long-term caching of assets.
All assets in your entry points are copied (and possibly transformed) to public/assets/
and the file names modified, so that they contain the content hash of the given file.
It also provides Twig functions to use these translated paths transparently in a symfony application.
In Twig the original filename is given to the asset*
function and it automatically generates the HTML reference for the hashed file name.
Warning: the directory public/assets/
is completely cleared on cache clear, so it should exclusively be managed by this bundle.
All requests to the assets/
directory can be cached for a long time, like with a expiry date in the far future or even immutable
headers.
Usage
The asset generation and preparation is done automatically. The assets are pregenerated on cache clear + warmup or on-the-fly generated if encountered with an empty cache.
In the configuration a mapping of namespaces to directories is defined. These namespaces are then used to retrieve paths to these files by using the @{namespace}/{path}
syntax:
In Twig, the following functions can be used:
Asset Processing
Currently only one asset processor is included in the bundle. Asset processors are chosen by file extension and are supposed to transform the given file content.
They are not supposed to alter the file in terms of minification, but to adjust import paths (like url(...)
in CSS) to the new paths.
Currently registered processors:
Processor | File Extensions | Purpose |
---|---|---|
CssProcessor |
.css |
Rewrite url(...) paths. |
Warning:
The asset processors are using the paths from the AssetCache
. This implies a race condition, as the processor can only rewrite paths of files that were already added to the cache. So files with a processor are deferred and only processed after all other files are finished (at least if the command / cache warmer is used). There still can be race conditions, if files with processors depend on each other.
Configuration
All configuration values with their description and defaults:
Commands
becklyn:assets:reset
The bundle provides a command to clear and warmup the cache:
Normally these commands are not required, as the bundle automatically registers as cache clearer and cache warmer.
becklyn:assets:namespaces
This command prints an overview over all registered namespaces. This is especially useful if you register paths programmatically outside of your configuration.
nginx Integration
Your project can cache the dumped assets indefinitely, as the file names are derived from the content.
All versions of assets-bundle with dependencies
ext-json Version *
becklyn/html-builder Version ^2.2.1
psr/cache Version ^1.0.1 || ^2.0.0 || ^3.0.0
symfony/cache-contracts Version ^2.5.0 || ^3.0.0
symfony/config Version ^5.4.3 || ^6.0.3
symfony/console Version ^5.4.3 || ^6.0.3
symfony/dependency-injection Version ^5.4.3 || ^6.0.3
symfony/filesystem Version ^5.4.3 || ^6.0.3
symfony/finder Version ^5.4.3 || ^6.0.3
symfony/http-kernel Version ^5.4.4 || ^6.0.4
symfony/mime Version ^5.4.3 || ^6.0.3
symfony/process Version ^5.4.3 || ^6.0.3
symfony/routing Version ^5.4.3 || ^6.0.3
symfony/service-contracts Version ^2.5.0 || ^3.0.0
twig/twig Version ^3.3.8