CODE
Asset Cache-Busting
Liquid code snippet to apply versioning to your css, javascript and other asset files to override caching.
v1.0.1
Change Log
- 1.0.1
- Changed date STRFTIME syntax to use %d instead of %e for day value to avoid leading space issue.
-
Create a Liquid variable in your <head> element so it can be used lower throughout your document.
{% comment %}<!-- Treehouse CODE v1.0.1 -->{% endcomment %} {% assign cacheControl = "now" | date: "%m%d%M%S" | prepend:'?v=' %}
We've used the strftime date syntax of
%m
(month),%d
(day),%M
(minute),%S
(second) to give us a unique number each time the page is loaded. -
Use
{{cacheControl}}
at the end of a file path to force a new cached version of that file, for example:<link rel="stylesheet" href="/_assets/css/styles.css{{cacheControl}}" type="text/css">
Which, once rendered, should give you something like:
<link rel="stylesheet" href="/_assets/css/styles.css?v=12134626" type="text/css">
Comments or questions? Head over to the Treepl CMS forum to discuss with the community.