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.
  1. Create a Liquid variable in your <head> element so it can be used lower throughout your document.

    <!-- Treehouse CODE v1.0.1 -->
    {% 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.

  2. 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:

    #04#26#
    <link rel="stylesheet" href="/_assets/css/styles.css?v=04261018" type="text/css">

Comments or questions? Head over to the Treepl CMS forum to discuss with the community.