Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Jun 4, 2024

Conversation

jedso
Copy link
Contributor

@jedso jedso commented May 6, 2024

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.

@jedso jedso requested a review from gwillz May 6, 2024 06:24
Copy link
Collaborator

@gwillz gwillz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following and nodding along until the sub_directory part. I assume this is because an the alternate docroot config?

We don't need to splatter that base config all through the templates, ew. Instead of BASE_PATH use DOCROOT.

I can see that's not obvious because we've not documented those base constants very well and they changed a fair bit after sprout 3.2.

Copy link
Collaborator

@gwillz gwillz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send it.

@gwillz gwillz merged commit ed4a620 into master Jun 4, 2024
@gwillz gwillz deleted the feat/twig-busty branch July 30, 2024 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants