ajaxray / gulp-buster-bundle
Symfony Bundle to integrate gulp-buster npm package for cache busting
Installs: 460
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/http-kernel: ~2.8
- symfony/twig-bundle: ~2.8
Requires (Dev)
- phpunit/phpunit: ~4.3
- satooshi/php-coveralls: dev-master
- symfony/framework-bundle: ~2.8
This package is not auto-updated.
Last update: 2024-10-26 19:00:03 UTC
README
When using gulp to manage assets of a Symfony application, this Bundle will help in cache busting with help of gulp-buster package.
Installation
Install the latest version with
$ composer require ajaxray/gulp-buster-bundle
Then enable the bundle in AppKernel -
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Ajaxray\GulpBusterBundle\GulpBusterBundle(), ); }
How to use
Assuming you are using gulp-buster to generate hashes for your web assets (javascript, css, images etc. static resources).
Now the next thing is using those hashes with your web assets. This bundle will make it easy by adding a Twig Filter. Here is how to use this filter in Twig views -
<link rel="stylesheet" href="{{ asset('css/example.min.css')|with_buster_hash }}">
If a hash is found for this file, it will be appended as query string with it's url -
<link rel="stylesheet" href="/css/example.min.css?v=771191ec8571a3f46afdb78f3e7bed17">
If no hash found for this file -
<link rel="stylesheet" href="/css/example.min.css?v=no-buster-hash-found">
That's all :)
Configuration
By default, this bundle assumes the following paths -
- busters.json (or any other name) file :
%kernel.root_dir%/../busters.json
- web dir:
%kernel.root_dir%/../web
- gulp dir (the dir of your gulpfile.js):
%kernel.root_dir%/..
If any/all of the above is different for you, you can configure from your app/config/config.yml
file using following keys -
gulp_buster: # if you've configured it to be in web dir busters_file: "%kernel.root_dir%/../web/busters.json" web_dir: "%kernel.root_dir%/relative/path/to/web/dir" gulp_dir: "%kernel.root_dir%/relative/path/to/dir"