sprout3
sprout3 copied to clipboard
Add busty Twig filter/function for cache busting URLs
Usage example:
<script src="{{ 'SKIN/assets/js/example.js'|busty }}"></script>
or
<script src="{{ busty('SKIN/assets/js/example.js') }}"></script>
There is also an optional sub_directory
argument for extra flexibility. For example, if Kohana::config('core.site_domain')
is set to "/", but the skin/
directory lives within a sub-directory such as app/
, then you can provide this:
<script src="{{ 'SKIN/assets/js/example.js'|busty('app/') }}"></script>
or
<script src="{{ busty('SKIN/assets/js/example.js', 'app/') }}"></script>
The end result is a URL with a query string parameter of _v
and the file's timestamp. The logic assumes that the URL provided does not already have query string parameters.