Download the PHP package kachkaev/assets-version-bundle without Composer
On this page you can find all versions of the php package kachkaev/assets-version-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kachkaev/assets-version-bundle
More information about kachkaev/assets-version-bundle
Files in kachkaev/assets-version-bundle
Package assets-version-bundle
Short Description Automates the process of updating assets version in Symfony2 & Symfony3 projects
License MIT
Homepage http://github.com/kachkaev/KachkaevAssetsVersionBundle
Informations about the package assets-version-bundle
KachkaevAssetsVersionBundle
⚠️ The repo is no longer maintained
See its forks, e.g. grizzlylab/KachkaevAssetsVersionBundle
Updating the assets version manually at each deploy is a real pain. This Symfony2 & Symfony3 bundle automates the process and thus makes your life a bit happier.
The bundle can read and write assets_version
parameter in app/config/parameters.yml
(or any other *.yml
file) from the Symfony console. The original file formatting is carefully preserved, so you won’t lose your comments or empty lines between the groups of parameters, if there are any.
Imagine the configuration of your project looks the following way:
app/config/config.yml
app/config/parameters.yml
You simply call bin/console assets-version:increment
, v042
changes to v043
and all your assets get a new URL: my_cosy_homepage.css?v042
→ my_cosy_homepage.css?v043
. More features are described below.
It is important to clear prod
cache after updating the assets version for a change to take effect (just as with any other application parameter).
Versioning your project’s assets is a common good practice. More on the assets_version
parameter can be found in the Symfony docs:
http://symfony.com/doc/2.6/reference/configuration/framework.html#assets-version
Installation
Run
Register the bundle in app/AppKernel.php
New to installing 3rd party bundles? Symfony docs will help:
http://symfony.com/doc/current/cookbook/bundles/installation.html
Configuration
Here is the default configuration for the bundle:
You don’t need to add anything to for these values to apply.
Option 1 (simple): Assets versioning is done on the server
If you are not using AsseticBundle for compressing your css and js files or if you call on the production server, you normally don’t want the changes of to show up in your git repository. All you have to do then is the following:
-
Modify your local copies of and :
-
Enable in (see the top of this file)
-
Commit and push local changes (this will also include a new line in and edits in both and )
-
Go to the server, and . Since you have a new entry in , you will be asked to confirm that you want to copy to . You do. Press enter.
- All done! Now each time you want to update the version of the assets, call these commands on the server:
Note: Replace with if you haven’t switched to Symfony3 yet.
Option 2 (recommended): Assets versioning is under the source control
If your app is running on multiple production servers or if you have a lot of css and js to compress with , you will benefit from keeping compiled assets and their version in the project’s git repo. It takes a bit more time to prepare for the deploy, but the rest happens nearly instantly. You won’t need UglifyCSS, UglifyJS or other assetic filters on your hosting and will be able to switch to any stable project version in a moment. A cheap server may struggle when compiling assets as this sometimes takes a lot of processor time, so you are saving yourself from that potential problem too.
Since is listed in , should be stored somewhere else.
-
Create and link to it from
app/config/assets_version.yml
app/config/config.yml
Do not add to !
-
Enable in (see the top of this file)
-
Add the following lines to :
-
That’s it, you are ready to commit what you have! Now each time you want to update the assets on the server, follow this routine:
on the local machineon the production server(s)
Make sure that the compiled assets are not in !
Tip: Type less and do more by keeping common command sequences in shell scripts. Examples:
bin/refresh_prod
(to be used on the local machine)
bin/update_from_repo
(to be used on the server)
Console commands
The bundle adds two commands to the symfony console: assets-version:increment
and assets-version:set
.
Usage examples:
The value for assets version must consist only of letters, numbers and the following characters: .-_
. Incrementing only works when the current parameter value is integer or has a numeric ending.
Please don’t forget to clear cache by calling bin/console cache:clear --env=prod
for changes to take effect in the production environment.
Capifony integration
If you are using Capifony you can automate increment of assets_version
during deployment using such code placed in deploy.rb
: