Karmabunny / sprout3

SproutCMS: content management and framework
http://getsproutcms.com
GNU General Public License v2.0
24 stars 3 forks source link

Add busty Twig filter/function for cache busting URLs #120

Closed jedso closed 3 months ago

jedso commented 4 months ago

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.